<?php
$phpapp="/immoweb";
$adminappname="portal";
$Language = new cLanguage();
$lang=$Language->LanguageId;
define("KEY", "wallahlalgitiha");

include $_SERVER['DOCUMENT_ROOT']."/vars.php";

/*require_once   $_SERVER['DOCUMENT_ROOT']."/portal/portal_loginsinfo.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/portal/portalinfo.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/portal/portal_portal_languagesinfo.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/portal/portal_contentinfo.php";*/
require_once   $_SERVER['DOCUMENT_ROOT']."/php/gtranslate/GTranslate.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/php/analytics/gapi.class.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/php/gchart/gChart.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/butterflyportal/phpmailer/php5/class.phpmailer.php";
require_once   $_SERVER['DOCUMENT_ROOT']."/php/redbean/rb.php";
//R::setup("mysql:host='".EW_CONN_HOST."';dbname='".EW_CONN_DB."','".EW_CONN_USER."','".EW_CONN_PASS."'");
R::setup('mysql:host='.EW_CONN_HOST.'; dbname='.EW_CONN_DB.'',''.EW_CONN_USER.'',''.EW_CONN_PASS.'');
RedBean_OODBBean::setFlagBeautifulColumnNames(false);
R::setStrictTyping(false);

if (!isset($_SESSION[EW_SESSION_STATUS])) $_SESSION[EW_SESSION_STATUS]="";





function autocomplete($input,$value,$operation,$parameters,$size)
{

	?>

	<div id="<?=$input?>div" style="display: inline">
	<input type="text" id="<?=$input?>" size="<?=$size?>"  class="ui-autocomplete-input ui-corner-all" autocomplete="on" value=""/>
	<input type="hidden" id="<?=$value?>" name="<?=$value?>" value=""/>
	</div>
	<script type="text/javascript">
	
	
	
	
	$(function() {
	
	
		$( "#<?=$input?>" ).autocomplete({
			minLength: 0,
			source: '/portlet.php?app=system&operation=<?=$operation?>&<?=$parameters?>',
			 
			select: function( event, ui ) {
				$( "#<?=$input?>" ).val( ui.item.label );
				$( "#<?=$value?>" ).val( ui.item.value );
				
				return false;
			}
		})
	
	});
	</script>
	<?php 
}




//get Parent Id of an object useful for tables that have parent point to it self and need to browse to parent

function getParentId($portal_object){
	if (getParameter("parentId")!=null && getParameter("parentId")!="NULL")
	{

		$sSql="SELECT $portal_object.parentId FROM `evigie_ao_inquery_status` WHERE $portal_object.id =".getParameter("parentId");
		$rs=$GLOBALS["conn"]->Execute($sSql);
		return "NULL";
		if ($rs->fields["parentId"]!="") return $rs->fields["parentId"];
	}
}

function Captcha()
{
	?>
	
	          Please type what you see in the image to confirme the operation.<br/><br/>
                
               <img src="/php/captcha/captcha.php" id="captcha" /><br/>
                <a href="#" onclick="
	    document.getElementById('captcha').src='/php/captcha/captcha.php?'+Math.random();
	    document.getElementById('captcha-form').focus();"
                   id="change-image">Not readable? Change text.</a><br/><br/>


                <input type="text" name="captcha" id="captcha-form" />
	<?php
	
}


function formatDate($date,$from,$to)
{
	$date = DateTime::createFromFormat($from, $date);
	return @$date->format($to);
	
}


function formatDatabaseDatetime($date)
{
	return formatDate($date,'Y-m-d H:i:s','d/m/Y');
}

function formatDatabaseDate($date)
{
	return formatDate($date,'Y-m-d','d/m/Y');
}


function getExecutionTime(){
	global $starttime;
	$mtime = microtime();
	$mtime = explode(" ",$mtime);
	$mtime = $mtime[1] + $mtime[0];
	$endtime = $mtime;
	$totaltime = ($endtime - $starttime);
	return round($totaltime,2);
}


function formatMoney($number, $fractional=false) {
    if ($fractional) {
        $number = sprintf('%.2f', $number);
    }
    while (true) {
        $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1 $2', $number);
        if ($replaced != $number) {
            $number = $replaced;
        } else {
            break;
        }
    }
    return $number;
}

function rand_colorCode(){
    $r = dechex(mt_rand(0,255)); // generate the red component
    $g = dechex(mt_rand(0,255)); // generate the green component
    $b = dechex(mt_rand(0,255)); // generate the blue component
    $rgb = $r.$g.$b;
    if($r == $g && $g == $b){
        $rgb = substr($rgb,0,3); // shorter version
    }
    return $rgb;
}

function parse_variables($input, $array)
{
    $search = preg_match_all('/{.*?}/', $input, $matches);

    for($i = 0; $i < $search; $i++)
    {
        $matches[0][$i] = str_replace(array('{', '}'), null, $matches[0][$i]);

    }

    foreach($matches[0] as $value)
    {
        $input = str_replace('{' . $value . '}', $array[$value], $input);
    }


    return $input;
}

function getFileContent($path,$realtive=true){
    if(function_exists('curl_init')){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $path);
        $data = curl_exec($ch);
    }
    else{

        $realtive=true; // bug in android

       $data=file_get_contents($path,$realtive);
    }

   // echo $data;
    return $data;
}


function refreshTable($table)
{

	
	make_master_details($table);
	$tableId=getObjByKey("portal_objects","id","name",$table);
	//echo $table." " .$tableId."<br/>";
	
	$text_types=array("longtext","text","blob","mediumtext","tinytext");
	if ($rs = ew_LoadRecordset("DESCRIBE $table"))
	{
		$firsttimestamp=true;
		while(! $rs->EOF)
		{
			$field=strtoupper($rs->fields["Field"]);
			$type=preg_split("/\(/",$rs->fields["Type"])[0];
	
			if (strpos($rs->fields["Type"],"("))
				$maxlen=preg_split("/\)/",preg_split("/\(/",$rs->fields["Type"])[1])[0];
			else
				$maxlen=50;
	
			if ($type=="enum") $maxlen=0;
	
	
	
			$options="AVCPDL";
			$select=null;
			$default=null;
			$textarea_cols=0;
			$textarea_rows=0;
			$enum_set_values=null;
			$values_column=null;
			$values_table=null;
	
	
			$auto_increment = strstr($rs->fields["Extra"], 'auto_increment') ? 1 : 0;
	
			if ($auto_increment) {
				$options='AVCPDR';
				// timestamps are read-only
			}else if ($type == 'timestamp') {
				if (!$firsttimestamp) {
					$firsttimestamp=false;
					$options='AVCPD';
				} else { // first timestamp
						
					$options='AVCPDR';
				}
	
			}
			// automatic support for Default values
			if ($rs->fields["Default"] != '' && $rs->fields["Default"] != 'NULL') {
				$default=$rs->fields["Default"];
			} else if ($auto_increment) {
				$default=0;
			}
	
			if (substr($type,0,3) == 'set') {
				$select="M";
			} else {
				$select="T";
			}
	
	
			// SETs and ENUMs get special treatment
			if ((substr($type,0,3) == 'set' || substr($type,0,4) == 'enum') && ! (($pos = strpos($type, '(')) === false)) {
				$indent = str_repeat(' ', 18);
				$outstr = substr($type, $pos + 2, -2);
				$outstr = explode("','", $outstr);
				$outstr = str_replace("''", "'",  $outstr);
				$outstr = str_replace('"', '\\"', $outstr);
				$outstr = implode('",'.PHP_EOL.$indent.'"', $outstr);
				$enum_set_values=$indent.''.$outstr;
			}
	
			// blobs -> textarea
	
	
	
			if (in_array($type, $text_types)) {
					
				$textarea_rows="5";
				$textarea_cols="50";
			}
	
	
	
			// for select
	
			$query    = "show create table $table";
			$result   = ew_LoadRecordset($query);
			$tableDef = preg_split('/\n/',$result->fields[1]);
	
			$values_table="";
			$values_column="";
			$constraint_arg="";
			while (list($key,$val) = each($tableDef)) {
	
	
				$words=preg_split("/[\s'`()]+/", $val);
				//echo $words[5]."<br/>";
				if ($words[1] == "CONSTRAINT" && $words[6]=="REFERENCES") {
					if (strtoupper($words[5])==$field) {
							
						$values_tableu="values_table='".$words[7]."', ";
						$values_columnu="values_column='".$words[8]."', ";
						$values_table=$words[7];
						$values_column=$words[8];
							
					}
	
				}
			}
	
			/*$sql="UPDATE portal_tables_fields SET  maxlen=$maxlen WHERE objectId=$tableId AND  fieldname='$field' ";
			 echo $sql.'<br/>';
			ew_LoadRecordset($sql);*/
	
			/*	$uploadpath=$rs->fields["uploadpath"];
			 $viewtag=get_enum_values("portal_tables_fields","viewtag")[0];
			$edittag=get_enum_values("portal_tables_fields","edittag")[0];
			if ($uploadpath!="") $edittag="Upload";*/
	
			//field exist and different Type
			$oldtype=getObjByKey("portal_tables_fields","type","objectId",$tableId,"fieldname",$field);
			if ($oldtype!="" && $oldtype!=$type)
			{
				//,viewtag='$viewtag',viewtag='$edittag'
				$sql="UPDATE portal_tables_fields SET type='$type', select_value='$select', options_value='$options', maxlen=$maxlen, default_value='$default', sort='Y', $values_tableu $values_columnu values_description=NULL, values_filters=NULL, textarea_rows=$textarea_rows, textarea_cols=$textarea_cols, lib_FR='$field', lib_AR='$field', lib_EN='$field' , custom_values=NULL WHERE objectId=$tableId AND  fieldname='$field'";
				//echo $sql.'<br/>';
				ShowSuccess("Field ".$field." has been successfully reloaded !");
				ew_LoadRecordset($sql);
					
			}
	
	
			$orderCmpnt=getMaxOrderObject("portal_tables_fields",null,"objectId",$tableId);
			//field does not exist
			if(getObjByKey("portal_tables_fields","fieldname","objectId",$tableId,"fieldname",$field)!=$field){
				$sql="INSERT IGNORE INTO portal_tables_fields (objectId,fieldname,type,select_value,options_value,maxlen,default_value,sort,values_table,values_column,values_description,values_filters,textarea_rows,textarea_cols,lib_FR,lib_AR,lib_EN,orderCmpnt,custom_values,edittag,uploadpath,edit_default,sub_values_table,sub_values_column,sub_values_description) VALUES
				($tableId,'$field','$type','$select','$options',$maxlen,'$default','Y','$values_table','$values_column',NULL,NULL,$textarea_rows,$textarea_cols,'$field','$field','$field',$orderCmpnt,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
				
				
				
				echo $sql.'<br/>';
				ShowSuccess("Field ".$field." has been successfully loaded !");
				ew_LoadRecordset($sql);
			}
	
			//echo $field." ".$type." ".$options." ".$select." ".$default." ".$textarea_cols." ".$textarea_rows." ".$enum_set_values." ".$maxlen." ".$values_column." ".$values_table;
			//	echo "<br/><br/>";
	
			$rs->MoveNext();
		}
	}
	
	}

function isLocal()
{
	if (strpos($_SERVER['SERVER_SOFTWARE'],"Win")) return true;
	return false;
}
function getPortalUrl(){
	$portalInstance=substr($_SERVER['HTTP_HOST'], 0, strpos ($_SERVER['HTTP_HOST'],"."));
	if ($portalInstance=="www") {
		$portalInstance=substr($_SERVER['HTTP_HOST'],  4);
		$portalInstance=substr($portalInstance,  0,strpos ($portalInstance,"."));
	}
//echo $portalInstance;
	return strtolower($portalInstance);

}

function getPortalHost(){

    return strtolower($_SERVER['HTTP_HOST']);

}

function getPortalAppVars(){
	global $portalId;
// echo "okokok";


	if (!$portalId){
        $portalId=getPortalId();
    }
	$sSql="SELECT  DISTINCT portal_app.`name` AS appname,
portal_portal_app_preferences.`name`,
portal_portal_app_preferences.`value`
FROM
portal_app
INNER JOIN portal_portal_app ON portal_portal_app.appId = portal_app.id
INNER JOIN portal_portal_app_preferences ON portal_portal_app_preferences.portal_portal_appId = portal_portal_app.id
WHERE 
portal_portal_app.portalId=".$portalId;
	 
	//echo $sSql;

	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);


	while ($rs && !$rs->EOF)  {

        //if it is a constant
        if (strpos($rs->fields["name"],"EW_")===false){
		$var="app_".$rs->fields["appname"]."_".$rs->fields["name"];
		global $$var;

		 define(strtoupper($var), $rs->fields["value"], TRUE);
		 
		$$var=$rs->fields["value"];
        }else{

            define(strtoupper($rs->fields["name"]), $rs->fields["value"], TRUE);

        }
		$rs->MoveNext();
	}
	
	if (!$rs || $rs->RecordCount()==0) {
ShowError("Portal Preferences are not set !");
exit();
}

}

function updateMeta($attr,$name,$attr_,$content)
{

    ?>
<script type="text/javascript">
$(function () { // dom ready
var $meta = $('meta[<?php echo $attr; ?>=<?php echo $name; ?>]').attr('<?php echo $attr_; ?>', '<?php echo $content; ?>');
$('body').text($meta.attr('<?php echo $attr_; ?>'));
});
</script>
<?php
}





function getAppLocales(){
global $portalId,$LANG;
	//get application locales
	$sSql="SELECT DISTINCT
	portal_app_locale.value_$LANG as value,
	portal_app_locale.`key`,
	portal_app.`name` as appname
	FROM
	portal_app_locale
	INNER JOIN portal_portal_app ON portal_app_locale.appId = portal_portal_app.appId
	INNER JOIN portal_app ON portal_portal_app.appId = portal_app.id
	WHERE portal_portal_app.portalId=$portalId and portal_app_locale.portalId is NULL";

	// echo $sSql."\n";
	$rs=$GLOBALS["conn"]->Execute($sSql);  Portal_log($sSql);
	while ($rs && !$rs->EOF)  {
	// echo $rs->fields["key"]."\n";
	
		$var="var_".$rs->fields["appname"]."_".$rs->fields["key"];
		global $$var;
		
		$$var=$rs->fields["value"];

		 
		//eval(" $"."var_".$rs->fields["name"]."_".$rs->fields["key"]."=\"".$rs->fields["value"]."\";");

		$rs->MoveNext();
	}

	//get custom application locales (overrided locales for current portal instance)


	$sSql="SELECT DISTINCT
	portal_app_locale.value_$LANG as value,
	portal_app_locale.`key`,
	portal_app.`name`
	FROM
	portal_app_locale
	INNER JOIN portal_portal_app ON portal_app_locale.appId = portal_portal_app.appId
	INNER JOIN portal_app ON portal_portal_app.appId = portal_app.id
	WHERE portal_portal_app.portalId=$portalId and portal_app_locale.portalId=$portalId";

	//     echo $sSql."\n";
	$rs=$GLOBALS["conn"]->Execute($sSql);  Portal_log($sSql);
	while ($rs &&  !$rs->EOF)  {
		// echo $rs->fields["key"];
		eval("$"."var_".$rs->fields["name"]."_".$rs->fields["key"]."=\"".$rs->fields["value"]."\";");

		$rs->MoveNext();
	}
}


function getPortalName()
{
	global $portalId;
	/*$sSql ="Select url From portal Where id=".getPortalId();
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	//if ($id=="") echo "Portal not found";
	return $rs->fields["url"];*/
	if (isset($GLOBALS["conn"])) return getObjByKey("portal","name","id",$portalId);
	return getPortalUrl();// //
}

function getPortalId()
{

	return getObjByKey("portal","id","url",getPortalUrl());
}

function getLayoutIcon($id)
{
	$sSql ="SELECT portal_layout.icon FROM portal_layout WHERE portal_layout.id = ".$id;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$icon=$rs->fields["icon"];
	
	return $icon;
}





function getParentObjectId($id,$portal_object)
{
	if (isset($_SESSION["parentId"]) && getParameter("parentId")==null) $_REQUEST["parentId"]=$_SESSION["parentId"];
	if (getParameter("parentId")==null) {
		if ($id==null && isset($_SESSION["id"])) $id=$_SESSION["id"];
		
		if ($id!=null){
	$sSql ="SELECT parentId FROM $portal_object WHERE id = ".$id;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	if ($rs->fields["parentId"]=="") $_REQUEST["parentId"]="NULL";
	$_REQUEST["parentId"]=$rs->fields["parentId"];
		}
	if (! isset($_REQUEST["parentId"]) || $_REQUEST["parentId"]=="") $_REQUEST["parentId"]="NULL";
	}
	//echo $_REQUEST["parentId"];
	$_SESSION["parentId"]=$_REQUEST["parentId"];
	return $_REQUEST["parentId"];
	
}

function getAgencyId()
{
    return null;
	global $international,$defaultCountry,$defaultCity,$portalId;
	if (isset($_REQUEST["portalId"])) $portalId=$_REQUEST["portalId"];

	//echo $agencyName;
	$sSql ="Select immo_agencys.* From immo_agencys Where portalId= '".$portalId."'";
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$international=$rs->fields["international"];
	$defaultCountry=$rs->fields["defaultCountry"];
	$defaultCity=$rs->fields["defaultCity"];
	return $rs->fields["id"];
}

function Portal_log($str)
{

	if (EW_DEBUG_ENABLED) echo "<span class='portal_log'>".$str."</span><br/>";
}



function curPageURL() {
	$pageURL = 'http';
	if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
		$pageURL .= "s";
	}
	$pageURL .= "://";
	if ($_SERVER["SERVER_PORT"] != "80") {
		$pageURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
	} else {
		$pageURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
	}
	return $pageURL;
}

function curPageURI() {
	$pageURL = $_SERVER["REQUEST_URI"];
	return $pageURL;
}



function MoveObject($id,$objectName,$direction)
{
	global $portalId;

	
	if ($direction=="Up" || $direction=="Down")    {
		$sSql="Select orderCmpnt  From $objectName  Where id=".$id;
		$rs=$GLOBALS["conn"]->Execute($sSql);
		$OldOrder=$rs->fields["orderCmpnt"];
		$sign=">";
		$Order="ASC";
		if ($direction=="Up") {
			$Order="DESC"; $sign="<";
		}
		$portalwhere="";
		if (ColumnExist($objectName, "portalId")) $portalwhere="portalId <=> ".$portalId." And";
		$sSql="Select id,orderCmpnt From $objectName Where $portalwhere  id <> ".$id." And orderCmpnt ".$sign." ".$OldOrder."  Order By orderCmpnt  ".$Order;
		 //echo $sSql."<br/>";
		$rs=$GLOBALS["conn"]->Execute($sSql);
		$NewId=$rs->fields["id"];
		$NewOrder=$rs->fields["orderCmpnt"];
		if ($NewId){
			$GLOBALS["conn"]->BeginTrans();
		$sUpdateSql = "UPDATE $objectName SET orderCmpnt=1000 WHERE id=".$id;

//echo $sUpdateSql."<br/>";
		$GLOBALS["conn"]->Execute($sUpdateSql);
		
		$sUpdateSql = "UPDATE $objectName SET orderCmpnt=".$OldOrder." WHERE id=".$NewId;

//	 echo $sUpdateSql."<br/>";
		$GLOBALS["conn"]->Execute($sUpdateSql);
		$sUpdateSql = "UPDATE $objectName SET orderCmpnt=". $NewOrder." WHERE id=".$id;
		
	//	echo $sUpdateSql."<br/>";
		
		$GLOBALS["conn"]->Execute($sUpdateSql);
		
		$GLOBALS["conn"]->CommitTrans();
		}
		//if (!EW_DEBUG_ENABLED) header("Location: ".ew_ScriptName()."?order=orderCmpnt&ordertype=ASC&operation=reset"); 
			
		//	echo "<script>window.location='".ew_ScriptName()."?order=orderCmpnt&ordertype=ASC';</script>";
	//	exit();
	}
}


function getMaxOrderPage($targetPortalId=null)
{
	 global $portalId;
	 if (!$targetPortalId) $targetPortalId=$portalId;
	$sSql= "Select Max(portal_pages.orderCmpnt) As maxorder
    	From portal_pages
		where type='P'
    	Group By portal_pages.portalId
    	Having portal_pages.portalId = ".$targetPortalId;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	if (!$rs) return 1;
	return $rs->fields["maxorder"]+1;
}

function getMaxOrderObject($object,$targetPortalId=null,$key=null,$value=null)
{
    global $portalId;
    $where="";
    if ($key!=null && $value!=null) $where=" where $key='$value' ";
    if (!$targetPortalId) $targetPortalId=$portalId;
    $sSql= "Select Max($object.orderCmpnt) As maxorder
    	From $object $where";
    if (ColumnExist($object,"portalId"))
    {
    	$sSql.="Group By $object.portalId Having $object.portalId = ".$targetPortalId;
    }
  //  echo $sSql."<br/>";
    $rs=$GLOBALS["conn"]->Execute($sSql);
    if (!$rs) return 1;
    return $rs->fields["maxorder"]+1;
}

function checkAndResetOrder($table,$filter,$filterValue)
{

	if (checkorders($table,$filter,$filterValue)==false)
	{
		//reset order

		$rs=ew_LoadRecordset("SELECT * FROM $table WHERE $filter=$filterValue order by orderCmpnt ASC");

		while(!$rs->EOF)
		{
			//echo $rs->fields["id"]." ".$rs->fields["orderCmpnt"]." ".getMaxOrderObject($table,null,"objectId",$filterValue);
			updateObjByKey($table,"id",$rs->fields["id"],"orderCmpnt",getMaxOrderObject($table,null,$filter,$filterValue));
			//echo "<br>";

			$rs->Movenext();
		}

	}}
	
function checkorders($table,$filter,$value)
{
	
	$SQL="SELECT
count(DISTINCT table1.id ) as cnt
FROM
$table table1
INNER JOIN $table table2 ON table1.id <> table2.id
where table1.orderCmpnt = table2.orderCmpnt and table1.$filter='$value' and table2.$filter='$value'";
//	echo $SQL;
	$rs=ew_LoadRecordset($SQL);
	if ($rs->fields['cnt']==0) return true;
	return false;
}



function get_enum_values( $table, $field )
{
	$rs=ew_LoadRecordset( "SHOW COLUMNS FROM $table WHERE Field = '$field'");
	$type = $rs->fields["Type"];
	preg_match('/^enum\((.*)\)$/', $type, $matches);
	foreach( explode(',', $matches[1]) as $value )
	{
		$enum[] = trim( $value, "'" );
	}
	
	return $enum;
}

function canView($object,$id)
{
return canDo($object,$id,"R");
}


function canAdd($object,$id)
{
	return canDo($object,$id,"A");
}


function canRemove($object,$id)
{
	return canDo($object,$id,"D");
}

function canEdit($object,$id)
{
	return canDo($object,$id,"C");
}

function inGroup($groupName)
{
	global $portalId;
	$groups=getUserGroupsById(getCurrentUserId());
	
	//if is superadministrator view all ressources without permissions
	if (in_array( getObjByKey("portal_groups","id","name",$groupName,"portalId",$portalId), $groups)) return true;
	return false;
}

function canDo($object,$id,$operation)
{
	global $portalId;
	$groups=getUserGroupsById(getCurrentUserId());
	 
	//if is superadministrator view all ressources without permissions
	if (in_array( getObjByKey("portal_groups","id","name","SuperAdministrator","portalId",$portalId), $groups)) return true;
	// if (getCurrentUserLevel()<=0) return true;
	/// return true;



	$sSql="SELECT * FROM portal_credentials
WHERE
portal_credentials.acces = '$operation' AND
portal_credentials.objectName = ".getObjByKey("portal_objects","id","name",$object)." AND
portal_credentials.objectId = $id AND groupId in (";
	//SELECT groupId FROM portal_groups_users WHERE userId = ".getCurrentUserId().")"

	foreach ($groups as $group)
	{
		//    echo $group."<br/>";
		$sSql .="$group ,";
	}

	$sSql .="-1)";

	//echo $sSql;

	$rs=$GLOBALS["conn"]->Execute($sSql);
	//echo "rs ".$rs->RecordCount();
	if ($rs==null) return false;
	//  echo "rs ".$rs->RecordCount();
	if ($rs->RecordCount()>0) return true;

	$application=preg_split("/_/", getObjByKey("portal_objects","name","id",$id))[0];

	if ($application=="") return  true;
	if (!in_array($application, getPortalApplications())) return false;

	return false;

}


function  getPortalApplications()
{
	global $portalId;
	$arr=array();
	$SQL="SELECT
portal_app.`name`
FROM
portal_app
INNER JOIN portal_portal_app ON portal_portal_app.appId = portal_app.id
WHERE
portal_portal_app.portalId = $portalId";
	$rs=ew_LoadRecordset($SQL);
	//echo $SQL;

	while ($rs && !$rs->EOF) {
	
	
		
	array_push($arr, $rs->fields["name"]);
		$rs->MoveNext();
	
	}
	return $arr;
}

function getCurrentUserId()
{
    global $portalId;
    return getObjByKey("portal_logins","id","portalId",$portalId,"login",CurrentUserName());


}

function getUserGroupsById($id)
{
    global $portalId;
    $sSql="SELECT groupId FROM portal_groups_users WHERE userId = $id";
    //echo $sSql;
    $rs=$GLOBALS["conn"]->Execute($sSql);
    $groups=array();
    $i=0;
    if ($rs!=null){

    while (!$rs->EOF)
    {

        $groups[$i++]=$rs->fields["groupId"];
        $rs->MoveNext();
    }
    }
    $groups[$i]=getObjByKey("portal_groups","id","name","Anonymous","portalId",$portalId);
    return $groups;
}

function getMaxOrderPortletInContainer($pageId,$container)
{
	$sSql="Select Max(Distinct portal_portletpage.`orderCmpnt`)+1  As maxorder
				From portal_portletpage
				Where portal_portletpage.pageId = ".$pageId." And portal_portletpage.place = '".$container."'";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["maxorder"];
}

function getPortalMenu($parentId,$order){
	global $LANG,$portalId;
    $op="=";
    if ($parentId=="null")    $op="<=>";
	$sSql ="Select logo_file,id, name, title_".$LANG." as title,type , redirectLink as url From portal_pages Where type<>'S' and active='Y' and visibility='Y' and parentId $op $parentId and portalId=".$portalId." Order By orderCmpnt ".$order;

	Portal_log($sSql);
	return $GLOBALS["conn"]->Execute($sSql);
}
function CopyContents($key,$targetPortalId)
{

	foreach ($_POST["key_m"] as $id)
	{
		CopyContent($id,$targetPortalId);
	}
return true;
}

function CopyContent($id,$targetPortalId)
{
    set_time_limit(0);
	global $portalId;
	$copy="";
	if ($targetPortalId==null) {
		$targetPortalId=$portalId; $copy="_copy";
	}
	$newauthoringId=getAuthoringTemplateIdByName(getAuthoringTemplateNameById(getAuthoringTemplateIdByContent($id)),$targetPortalId);

	$sSql="INSERT INTO portal_content (workflow_statusId,authoringtemplateId,name,lib,portalId,date,addDate,editDate,defaultLanguage,localized,workflowId,workflow_stageId) select workflow_statusId,$newauthoringId,CONCAT(name,'".$copy."'),CONCAT(lib,'".$copy."'),".$targetPortalId.",date,'".ew_CurrentDateTime()."','".ew_CurrentDateTime()."',defaultLanguage,localized,workflowId,workflow_stageId from portal_content where id=".$id;
	//echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$newid=getLastId();
	$sSql="INSERT INTO portal_contentvalues (contentId,authoringtemplate_elementId,TextField_FR_value,TextField_EN_value,TextField_AR_value,TextArea_FR_value,TextArea_EN_value,TextArea_AR_value,RichText_FR_value,RichText_EN_value,RichText_AR_value,Datevalue,InternalLinkvalue,Flashvalue,FlashWidthvalue,FlashHeightvalue,FlashVarsvalue,Imagevalue,Imagevalue_ext,Queryvalue,authoringelementId,portalId) select ".$newid.",authoringtemplate_elementId,TextField_FR_value,TextField_EN_value,TextField_AR_value,TextArea_FR_value,TextArea_EN_value,TextArea_AR_value,RichText_FR_value,RichText_EN_value,RichText_AR_value,Datevalue,InternalLinkvalue,Flashvalue,FlashWidthvalue,FlashHeightvalue,FlashVarsvalue,Imagevalue,Imagevalue_ext,Queryvalue,authoringelementId,portalId from portal_contentvalues where contentId=".$id;
	//echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$authoringId=getAuthoringTemplateIdByContent($newid);
	$wokflowId=getWorkflowId($authoringId);
	restartWorkflow($newid,$workflowId,"portal_content");
	return true;
}


function getAuthoringTemplateNameById($id)
{

    return getObjByKey("portal_authoringtemplate","name","id",$id);
}

function getAuthoringTemplateIdByName($name,$targetportal = null)
{
if ($targetportal!=null) return getObjByKey("portal_authoringtemplate","id","portalId",$targetportal,"name",$name);
    return getObjByKey("portal_authoringtemplate","id","name",$name);
}


function TagContents($key,$tagId)
{
	foreach ($_POST["key_m"] as $id)
	{
		TagContent($id,$tagId);
	}
	return true;
}


function CopyPortalPreferences($key,$targetPortalId)
{
    global $portalId;
    $copy="";
    if ($targetPortalId==null) {
        $targetPortalId=$portalId;
        $copy="_copy";
    }
    foreach ($_POST[$key] as $id)
    {
        $portal_portal_appId=getObjByKey("portal_portal_app_preferences","portal_portal_appId","id",$id);
        $portal_appId=getObjByKey("portal_portal_app","appId","id",$portal_portal_appId);
        $portal_portal_appId=getObjByKey("portal_portal_app","id","appId",$portal_appId,"portalId",$targetPortalId);
       insertObjByKey("portal_portal_app_preferences","name".$copy,"value","portal_portal_appId",getObjByKey("portal_portal_app_preferences","name","id",$id),getObjByKey("portal_portal_app_preferences","value","id",$id),$portal_portal_appId);
    }
}

function TagContent($id,$tagId)
{

	insertObjByKey("portal_tag_content","contentId","tagId",$id,$tagId);
}

function CopyAuthorings($key,$targetPortalId)
{
	foreach ($_POST["key_m"] as $id)
	{
		CopyAuthoring($id,$targetPortalId);
	}
	return true;
}

function isPortalSuperAdmin(){
global $portalId;	

	$groups=getUserGroupsById(getCurrentUserId());
	
	
	if (in_array(getObjByKey("portal_groups","id","name","SuperAdministrator","portalId",$portalId), $groups))
	{
	
	
	return true;
	}
	
	return false;
}

function TranslateVars()
{
    foreach ($_POST["key_m"] as $id)
    {
        TranslateVar($id);
    }
    return true;
}


function TranslateVar($id)
{
    $entry=getObjByKey("portal_app_locale","value_FR","id",$id);
    $entry=str_replace("\n","",$entry);
    $entry=str_replace("\t","",$entry);
    $entry=str_replace("\r","",$entry);
    //
 /* $entry_EN =  http_request (HTTP_METH_GET , "http://translate.google.co.ma/translate_a/t?client=t&text=bonjour&hl=fr&sl=fr&tl=en" );
    echo $entry_EN;*/
   //
  try{
      $gt = new Gtranslate;
        $gt->setApiKey("");
    $entry_EN=$gt->fr_to_en($entry);
    $entry_AR=$gt->fr_to_ar($entry);
      updateObjByKey("portal_app_locale","id",$id,"value_EN",$entry_EN,"value_AR",$entry_AR);

  } catch (GTranslateException $ge) {
        echo $ge->getMessage();
    }
}

function targetPortal()
{
	global $form,$portalId;
	if (isPortalSuperAdmin()){
		$sSql="SELECT name as lib,id as value FROM portal WHERE id!=".$portalId;

		//echo $sSql;
		?>

<select  title="" name="portal" id="portal" style=" vertical-align: top; margin-top: 8px;">
<option value="none"></option>
<?php

      $rs2=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs2->EOF)  { 
 	
		  ?>
<option   value="<?php echo $rs2->fields["value"]; ?>"><?php echo $rs2->fields["lib"]; ?></option>

				  <?php
		  $rs2->MoveNext();    
		  }


	
?>
</select>
<input type="hidden" name="targetportal" id="targetportal" value="none"/>

<script>
$("#<?php echo $form; ?>").append($("#targetportal"));
$("#portal").change(function(){
$("#targetportal").val($(this).val());
		});
</script>
<?php } }



function targetGroups()
{
    global $form,$portalId;
    if (isPortalSuperAdmin()){
        $sSql="SELECT name as lib,id as value FROM portal_groups WHERE portalId=$portalId";

        //echo $sSql;
        ?>

    <select  title="" name="group" id="group" style=" vertical-align: top; margin-top: 8px;">
        <option value="none"></option>
        <?php

        $rs2=$GLOBALS["conn"]->Execute($sSql);

        while ( !$rs2->EOF)  {

            ?>
            <option   value="<?php echo $rs2->fields["value"]; ?>"><?php echo $rs2->fields["lib"]; ?></option>

            <?php
            $rs2->MoveNext();
        }



        ?>
    </select>
    <table class="ewItemTable"><tbody><tr><td><label><input type="radio" name="right" id="right" title="" value="R" checked="checked">Read</label>
    </td><td><label><input type="radio" name="right" id="right" title="" value="A">Add</label>
    </td><td><label><input type="radio" name="right" id="right" title="" value="E">Edit</label>
    </td><td><label><input type="radio" name="right" id="right" title="" value="D">Delete</label>
    </td><td>&nbsp;</td></tr></tbody></table>

  


    <script>
       /* $("#<?php echo $form; ?>").append($("#targetgroup"));
        $("#<?php echo $form; ?>").append($("#right"));
        $("#group").change(function(){
            $("#targetgroup").val($(this).val());
        });

        $("#right").change(function(){
            $("#right").val($(this).val());
        });*/
    </script>
    <?php } }

function CopyAuthoring($id,$targetPortalId)
{
	global $portalId;
	$copy="";
	if ($targetPortalId==null) { $targetPortalId=$portalId; $copy="_copy";}
	$sSql="INSERT INTO portal_authoringtemplate (portalId,`name`,editDate,lib,workflowId,comment_workflowId) select ".$targetPortalId.",CONCAT(`name`,'".$copy."'),'".ew_CurrentDateTime()."',CONCAT(lib,' ".$copy."'),workflowId,comment_workflowId from portal_authoringtemplate where id=".$id;
	echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$newid=getLastId();
	$sSql="INSERT INTO portal_authoringtemplate_elements (authoringId,elementId,`name`) select ".$newid.",elementId,`name` from portal_authoringtemplate_elements where authoringId=".$id;
	echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return true;
}


function CopyPresentations($key,$targetPortalId)
{
	foreach ($_POST["key_m"] as $id)
	{
		CopyPresentation($id,$targetPortalId);
	}
	return true;
}

function CopyPresentation($id,$targetPortalId)
{
	global $portalId;
	$copy="";
	if ($targetPortalId==null) {
		$targetPortalId=$portalId; $copy="_copy";
	}
	$sSql="INSERT INTO portal_presentationtemplate (portalId,`name`,`code`,type,editDate,lib) select ".$targetPortalId.",CONCAT(`name`,'".$copy."'),`code`,type,'".ew_CurrentDateTime()."',CONCAT(lib,'".$copy."') from portal_presentationtemplate where id=".$id;
	echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return true;
}

function CopyLayouts($key,$targetPortalId)
{
	foreach ($_POST["key_m"] as $id)
	{
		CopyLayout($id,$targetPortalId);
	}
	return true;
}

function CopyLayout($id,$targetPortalId)
{
	$_REQUEST["operation"]="";
	global $portalId;
	$copy="";
	if ($targetPortalId==null) {
		$targetPortalId=$portalId; $copy="_copy";
	}

	$sSql= "insert into `portal_layout`(portalId, `name`, lib, layout, icon) SELECT  ".$targetPortalId.",	concat(name,\"".$copy."\") as `name` ,	concat(lib,\"".$copy."\") as lib,	layout,	icon FROM `portal_layout` Where id =".$id;
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
}

function SetRights($key,$objectName,$groupId,$right)
{

	foreach ($_REQUEST[$key] as $id)
    {
        SetRight($id,$objectName,$groupId,$right);
    }
	return true;
}

function SetRight($id,$objectName,$groupId,$right){
    global $portalId;


    insertObjByKey("portal_credentials","objectId","objectName","acces","groupId","portalId",$id,$objectName,$right,$groupId,$portalId);
    //insertObjByKey("portal_credentials","objectId",$id,"objectName",$objectName,"acces",$right,"groupId",$groupId,"portalId",$portalId);

}

function RevokeRight($id,$objectName,$groupId,$right){
    global $portalId;

    removeObjByKey("portal_credentials","objectId",$id,"objectName",$objectName,"acces",$right,"groupId",$groupId,"portalId",$portalId);
}



function getPortletPreference($name)
{
    global $portletID;
    $var="portlet_".$portletID."_".$name;
    global $$var;
    return $$var;
}


function CopyPages($key,$targetPortalId)
{

	foreach ($_POST["key_m"] as $id)
	{
		CopyPage($id,$targetPortalId);
	}
	return true;
}


function CopyPage($id,$targetPortalId)
{
    $GLOBALS["conn"]->BeginTrans();
    set_time_limit(0);
	global $portalId;
	$copy="";
	if ($targetPortalId==null) {
		$targetPortalId=$portalId; $copy="_copy";
	}
	//define("EW_DEBUG_ENABLED", TRUE);
	$_REQUEST["operation"]="";
	$sSql= "insert into portal_pages(name, title_FR, title_AR, title_EN, type, redirectLink, portalId,  parentId, layoutId,orderCmpnt,visibility,active) Select concat(name,\"".$copy."\") as name, title_FR, title_AR, title_EN, type, redirectLink, ".$targetPortalId.",  parentId, layoutId,".getMaxOrderPage($targetPortalId).",visibility,active From portal_pages Where id =".$id;
	//if (EW_DEBUG_ENABLED)
      echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);

	//get new page id

	$sSql= "SELECT LAST_INSERT_ID() as id";
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$newid=$rs->fields["id"];



	//update layout and parentId


	$sSql="UPDATE portal_pages SET parentId=".getObjByKey("portal_pages","id","name",getObjByKey("portal_pages","name","id",getObjByKey("portal_pages","parentId","id",$id),"portalId",$portalId),"portalId",$targetPortalId)." , layoutId=".getObjByKey("portal_layout","id","name",getObjByKey("portal_layout","name","id",getObjByKey("portal_pages","layoutId","id",$id)),"portalId",$targetPortalId)." WHERE id=".$newid;
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);

	// setup portlets and their preferences in the new page

	$sSql="Select  portal_portletpage.pageId as pageId , portal_portlet_preferences.name as name,
  portal_portlet_preferences.value as value,
  portal_portletpage.portletId,
  portal_portletpage.place,
  portal_portletpage.orderCmpnt,
  portal_portletpage.id as id
From portal_portlet_preferences Inner Join
  portal_portletpage On portal_portlet_preferences.portlet_page_id =
    portal_portletpage.id
Where portal_portletpage.pageId = ".$id."
	Order By portal_portletpage.id   ";
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$old_portletpageId="";
	$portletpageId="";
	$portletId_nopref=" -1 ";
	while ( !$rs->EOF)  {
		$name=$rs->fields["name"];
		$value=$rs->fields["value"];

		if ($old_portletpageId!=$rs->fields["id"]){
			$old_portletpageId=$rs->fields["id"];
			$sSql= "insert into portal_portletpage(pageId, portletId, place, `orderCmpnt`,portalId) values ('".$newid."','".$rs->fields["portletId"]."','".$rs->fields["place"]."','".$rs->fields["orderCmpnt"]."',$targetPortalId)";
			if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
			$rs4=$GLOBALS["conn"]->Execute($sSql);

			$sSql= "SELECT LAST_INSERT_ID() as id";
			if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
			$rs2=$GLOBALS["conn"]->Execute($sSql);
			$portletpageId=$rs2->fields["id"];
			$portletId_nopref.=", ".$portletpageId;
		}


		$sSql= "insert into portal_portlet_preferences(portlet_page_id,name,value,portalId) values ($portletpageId,'$name','$value',$targetPortalId)";
		if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
		$rs3=$GLOBALS["conn"]->Execute($sSql);

		$rs->MoveNext();
	}

/*	$sSql="Select * From portal_portletpage Where portal_portletpage.pageId = '".$id."' And portal_portletpage.id not in ( ".$portletId_nopref." )";
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while ( !$rs->EOF)  {
		$sSql= "insert into portal_portletpage(pageId, portletId, place, `orderCmpnt`) values ('".$newid."','".$rs->fields["portletId"]."','".$rs->fields["place"]."','".$rs->fields["orderCmpnt"]."')";
		if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
		$rs4=$GLOBALS["conn"]->Execute($sSql);
		$rs->MoveNext();
	}
*/

	//if (!EW_DEBUG_ENABLED)
      //  echo "<script>window.location='".ew_ScriptName()."?order=orderCmpnt&ordertype=ASC';</script>";
    $GLOBALS["conn"]->CommitTrans();
   // exit();
}

function setDefaultPortletPreferences($portletId)
{
    global $portalId;
	$reload=false;
	$sSql= "insert into portal_portlet_preferences_names(portlet_id,name,query) values ($portletId,'Skin','Select portal_skins.name as value, portal_skins.lib From portal_skins where 1=1 ')";
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$GLOBALS["conn"]->Execute($sSql);
	if (getLastId()) $reload=true;
	$sSql="Select UCASE(value) as value From portal_languages";
	if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while ( !$rs->EOF)  {

		$sSql= "insert into portal_portlet_preferences_names(portlet_id,name,query) values ('".$portletId."','Title_".$rs->fields["value"]."','')";
		if (EW_DEBUG_ENABLED) echo $sSql."<br/>";
		$GLOBALS["conn"]->Execute($sSql);
		if (getLastId()) $reload=true;

		$rs->MoveNext();
	}

    if ($reload) header("Location: ".addParameter("succes","Default Portlet Preferences has been succesfully reloaded!"));
}



function setDefaultPortalAppPreferences($coupleId)
{
    global $portalId;

    $reload=false;


    $sSql ="SELECT * FROM `portal_portal_app_preferences` WHERE `portal_portal_appId`=$coupleId;";
   // echo $sSql ;
    $rs=$GLOBALS["conn"]->Execute($sSql);

    $exclusion=array();

    while (!$rs->EOF)  {

        array_push($exclusion,$rs->fields["name"]);

        $rs->MoveNext();
    }



    $sSql ="Select preferences_names.name,preferences_names.defaultvalue ".
        "From portal_app application Inner Join ".
        "portal_app_preferences_names preferences_names On application.id = preferences_names.appId ".
        "Inner Join ".
        "portal_portal_app portal_application On application.id = portal_application.appId ".
        "Where portal_application.id = ".$coupleId;
   // echo $sSql ."<br/>";
    $rs=$GLOBALS["conn"]->Execute($sSql);
    $paramToNotDelete="(";
    while ( !$rs->EOF)  {
        $name=$rs->fields["name"];
        $defaultvalue=$rs->fields["defaultvalue"];
        if (in_array($name,$exclusion)==false)
        {




            $sSql="INSERT INTO `portal_portal_app_preferences` (`id` ,`portal_portal_appId` ,`name` ,`value`) VALUES (NULL , '$coupleId', '$name', '$defaultvalue');";
          //  echo $sSql ."<br/>";
            $reload=true;
            $rsi=$GLOBALS["conn"]->Execute($sSql);
        }
        $paramToNotDelete.=" `name`='".$name."' OR ";

        $rs->MoveNext();
    }
    $paramToNotDelete.=" 1=2 )";
    if( $paramToNotDelete!="( 1=2 )" )	{
        $sSql="DELETE FROM `portal_portal_app_preferences` WHERE `portal_portal_appId`=".$coupleId." and not ".$paramToNotDelete;
      //  echo $sSql ."<br/>";
       $rsi=$GLOBALS["conn"]->Execute($sSql);
    }


 if ($reload) header("Location: ".addParameter("succes","Application Preferences has been succesfully reloaded!"));
}


//echo $_SERVER['SERVER_NAME'];



function addParameter($param,$value,$curPageUri="curPageURI") {


	if ($curPageUri=="curPageURI") $curPageUri=curPageURI();
	$pageUri=$curPageUri;


    if (strpos($pageUri,$param."=")!==false)
    {

        return str_replace($param."=",$param."=".$value."&",$pageUri);

    }else{

	if (strpos($curPageUri,"?")!==false) $separator="&"; else  $separator="?";


	if (strpos($curPageUri,"&".$param."=")!==false) {

		return str_replace("&".$param."=".$param,"&".$param."=".$value,$pageUri);
	}elseif (strpos($curPageUri,"?".$param."=")!==false) {

		return str_replace("?".$param."=".$param,"?".$param."=".$value,$pageUri);
	}
	$pageUri.=$separator.$param."=".$value;
    }
	return $pageUri;
}

function getmasterdetails($detail_table,$master_table)
{
	$SQL    = "show create table $detail_table";
	//echo $SQL;
	$rs   = ew_LoadRecordset($SQL);
	$tableDef = preg_split('/\n/',$rs->fields[1]);

	$constraint_arg="";
	while (list($key,$val) = each($tableDef)) {


//echo $val;

		$words=preg_split("/[\s'`()]+/", $val);
		if ($words[1] == "CONSTRAINT" && $words[6]=="REFERENCES" && $words[7]==$master_table) {
			//echo $words[5];
			return $words[5];
		}
	}
	return null;
}
function make_master_details($master_table)
{
$GLOBALS["conn"]->BeginTrans();
$Sql ="SELECT
DISTINCT information_schema.`TABLES`.TABLE_NAME as tablename
FROM
information_schema.`TABLES` ,
portal_portal_app,
 portal_app where
information_schema.`TABLES`.TABLE_SCHEMA = DATABASE() and portal_app.id = portal_portal_app.appId and
information_schema.`TABLES`.TABLE_NAME  like concat('%', portal_app.`name`, '%')";

$rstables=$GLOBALS["conn"]->Execute($Sql);

//echo $Sql;
$masterId=getObjByKey("portal_objects","id","name",$master_table);
while (!$rstables->EOF)  {
	$detail_table=$rstables->fields[0];

	$foreignKey=getmasterdetails($detail_table,$master_table);
	if ($foreignKey){
		$slaveId=getObjByKey("portal_objects","id","name",$detail_table);
		//echo $foreignKey." ".$detail_table." <br/>";
		$sql="INSERT IGNORE INTO portal_masterdetail VALUES (NULL,$masterId,$slaveId,'$foreignKey','N','Normal')";
		//echo $sql.'<br/>';
		ew_LoadRecordset($sql);
	}


	$rstables->MoveNext();
}


$GLOBALS["conn"]->CommitTrans();
}

function make_all_master_details()
{
	$GLOBALS["conn"]->BeginTrans();
	$Sql ="SELECT
DISTINCT information_schema.`TABLES`.TABLE_NAME as tablename
FROM
information_schema.`TABLES` ,
portal_portal_app,
 portal_app where
information_schema.`TABLES`.TABLE_SCHEMA = DATABASE() and portal_app.id = portal_portal_app.appId and
information_schema.`TABLES`.TABLE_NAME  like concat('%', portal_app.`name`, '%')";

	$rstables=$GLOBALS["conn"]->Execute($Sql);

	
	while (!$rstables->EOF)  {
		$master_table=$rstables->fields[0];

		make_master_details($master_table);


		$rstables->MoveNext();
	}


	$GLOBALS["conn"]->CommitTrans();
}


function hashVar($str)
{

	

	return @preg_replace('/\#([a-zA-Z0-9_]+)\#/e',"$$1", $str);
}



function TemplateWithData($template,$data)
{

    foreach ($data as $key => $value)
    {

       $$key=$value;

    }

  /* $tmp_template=$template;
    $new_template="";


    $array=preg_split('#\[([a-zA-Z]*)\]#',$template);
    foreach ($array as $value)
    {

        $new_template.=$value ;

        $tmp_template=str_replace($value."[","",$tmp_template);

        $param=explode("]",$tmp_template);
        if ($param[0]!="")
        $new_template.= $data[$param[0]];
        $tmp_template=substr($tmp_template,strlen($param[0]));

    }



    return $new_template;*/

    return @preg_replace('/\[([a-zA-Z0-9_]+)\]/e',"$$1", $template);
}



function TemplateToPHP($template,$portletName)
{

	$template=str_replace("\'","\\\'",$template);
	$template=str_replace("\"","\\\"",$template);
	$template=str_replace("\n","",$template);
	$template=str_replace("\t","",$template);
	$template=str_replace("\r","",$template);
	//return $template;

 /* calling php functions from cms another powersource for BP, but to use with moderation, may be there is security issue here.
 We have to dress a list of non risky functions to give to cms administrators
 a new table should be created and will contain this list.
   */
    $pattern='<systemfunction name=\\\"([a-z,A-Z,0-9]*)\\(([a-z,A-Z,0-9]*),([a-z,A-Z,0-9]*)\\)\\\">';
    $replacement='span>"; if ($1($2,$3)){ echo "</span';

    //without parameters
    $pattern='<systemfunction name=\\\"([a-z,A-Z,0-9]*)\\(\\)\\\">';
    $replacement='span>"; if ($1()){ echo "</span';


    $template=preg_replace($pattern, $replacement, $template);

    $pattern='</systemfunction>';
    $replacement='span>"; } echo "</span';
    $template=preg_replace($pattern, $replacement, $template);

	$pattern='<display name=\\\"([a-z,A-Z,0-9]*)\\\"/>';
	$replacement='".$$1."';
	$template=preg_replace($pattern, $replacement, $template);


	$pattern='<system name=\\\"([a-z,A-Z,0-9]*)\\\"/>';
	$replacement='".$system_$1."';
	$template=preg_replace($pattern, $replacement, $template);




	$pattern='<prefs name=\\\"([a-z,A-Z,0-9]*)\\\"/>';
	$replacement='".$portlet_'.$portletName.'_$1."';
	$template=preg_replace($pattern, $replacement, $template);
	
	
	$pattern='<param name=\\\"([a-z,A-Z,0-9]*)\\\"/>';
	$replacement='".getParameter("$1")."';
	$template=preg_replace($pattern, $replacement, $template);


	$pattern='<pagination name=\\\"([a-z,A-Z,0-9]*)\\\"/>';
	$replacement='".$pagination_$1."';
	$template=preg_replace($pattern, $replacement, $template);


	$pattern='<include tag=\\\"([a-z,A-Z,0-9]*)\\\"/>';
	//$replacement='".if (isset($portlet_contenu_allow$1s) && $portlet_contenu_allow$1s==\"Yes\") include \'$1.php\';."';
		//$replacement='"; include("$1.php"); echo "';
	$replacement='span>"; include("$1.php"); echo "</span';
	$template=preg_replace($pattern, $replacement, $template);




	$template = "echo \"".$template."\";";
	$template=str_replace("<\".","\".",$template);
	$template=str_replace(".\">",".\"",$template);




	return $template;
}
function isLogged()
{

    return true;

}

function testcallfunction($i,$j,$k,$l)
{
    echo $i*$j*$k*$l;
    return true;

}

function getPortalLanguagesFilter(){
	$sSql = "Select languageId From portal_portal_languages Where portalId =".$_REQUEST["portalId"];
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$filter=" in (-1";
	while ( !$rs->EOF)  {

		$filter.=" , ".$rs->fields["languageId"];
		$rs->MoveNext();
	}
	$filter.=")";
	$_REQUEST["langfilter"]=$filter;
}

function getPortalLanguages(){
	$sSql = "Select portal_languages.value
	From portal_portal_languages Inner Join
	portal_languages On portal_portal_languages.languageId = portal_languages.id
	Where portal_portal_languages.portalId =".$_REQUEST["portalId"];
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$languages=array();
	while ( !$rs->EOF)  {
		array_push($languages, $rs->fields["value"]);
		$rs->MoveNext();
	}
	return $languages;
}

function HidePortalLanguages(){
    global $LANG,$lang,$portalId;
    if ($portalId==17) return;
   echo "<script type='text/javascript'>";

  /*
   	$sSql = "Select portal_languages.id
	From portal_portal_languages Inner Join
	portal_languages On portal_portal_languages.languageId = portal_languages.id
	Where portal_portal_languages.portalId = ".$_REQUEST["portalId"];
    $sSql="SELECT portal_languages.id From portal_languages WHERE portal_languages.`value` <> $LANG ";
	$filter="-1";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while ( !$rs->EOF)  {
		$filter.=",".$rs->fields["id"];
		$rs->MoveNext();
	}
	$sSql="Select UPPER(portal_languages.value) as value From portal_languages where id not in (".$filter.")";
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while ( !$rs->EOF)  {
        echo "alert('".$rs->fields["value"]."');";
		echo "$(\"input[id$='_".$rs->fields["value"]."']\").parent().parent().parent().hide();\n";
		echo "$(\"textarea[id$='_".$rs->fields["value"]."']\").parent().parent().parent().hide();\n";
		$rs->MoveNext();
	}*/



    $sSql="SELECT UPPER(portal_languages.value) as value From portal_languages WHERE portal_languages.`value` <> '$lang' ";

    $rs=$GLOBALS["conn"]->Execute($sSql);
    while ( !$rs->EOF)  {
       // echo $rs->fields["value"];
        echo "$(\"input[id$='_".$rs->fields["value"]."']\").parent().parent().parent().hide();\n";
        echo "$(\"textarea[id$='_".$rs->fields["value"]."']\").parent().parent().parent().hide();\n";
        $rs->MoveNext();
    }
   echo "</script>";
}


function getAuthoringElements()
{
    global $portalId;
	$sSql="Select portal_languages.value From portal_languages";

$language=array();
	Portal_log($sSql);
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);


		while ( !$rs->EOF)  {
		 	array_push($language,strtoupper($rs->fields["value"]));
			$rs->MoveNext();
		}

	$sSql="Select * From portal_authoringelement";
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$output="\"NULL\"";
	while ( !$rs->EOF)  {
		if ($rs->fields["multilang"]=="Y"){
		foreach ($language as $value)
		{
			$output.=",\"".strtoupper($rs->fields["name"])."_". $value."_\"";
		}
        }
		else
		$output.=",\"".strtoupper($rs->fields["name"])."\"";
		$rs->MoveNext();
	}
	echo $output;
}

function getPortalAppsFilter(){
	$sSql = "Select appId From portal_portal_app Where portalId = ".$_REQUEST["portalId"];
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$filter=" in (-1";
	while ( !$rs->EOF)  {

		$filter.=" , ".$rs->fields["appId"];
		$rs->MoveNext();
	}
	$filter.=")";
	$_REQUEST["portalappfilter"]=$filter;
}


function isPortalApp($TableName){
	global $portalId;
	if ($portalId=="") {
		$portalId=getPortalId();
		//echo  " Unknown Portal ! <br/>"; return TRUE;
	}
	$sSql = "Select portal_app.name
	From portal_portal_app Inner Join
	  portal_app On portal_portal_app.appId = portal_app.id
	Where portal_portal_app.portalId = ".$portalId;
	Portal_log($sSql);
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while (!$rs->EOF)  {
		$module=$rs->fields["name"];
		if (substr($TableName,0,strlen($module))==$module) return TRUE;
		$rs->MoveNext();
	}
	return FALSE;
}


function getPresentatationTemplate($template,$portletName,$type){
	global $portalId;
	if ($template=="") return "";
	$sSql ="Select presentationtemplate.code ".
		"From portal_presentationtemplate presentationtemplate INNER JOIN portal_typenames on presentationtemplate.type = portal_typenames.id ".
		"Where portalId=$portalId and presentationtemplate.name = '$template' and portal_typenames.type='$type' ";
	
	/*R
	 * Select portal_presentationtemplate.name as value,portal_presentationtemplate.lib as lib From portal_presentationtemplate INNER JOIN portal_typenames on presentationtemplate.type WHERE portal_typenames.type='H'
	 * */
	
	//echo $sSql;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return TemplateToPHP($rs->fields["code"],$portletName);
}


function insertCustomCSS($dir){
	global $portalId,$apppath,$appname;
	$sSql="Select css_file From portal_stylesheet Where dir = 'nnn' And portalId =".$portalId;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while ( !$rs->EOF)  {

		$css=$rs->fields["css_file"];
		//echo ew_DomainUrl()."/css/custom/".$css;
		echo getFileContent(ew_DomainUrl()."/css/custom/".$css, FILE_USE_INCLUDE_PATH);

		$rs->MoveNext();
	}


	$sSql="Select css_file From portal_stylesheet Where dir = '".$dir."' And portalId =".$portalId;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	while ( !$rs->EOF)  {

		$css=$rs->fields["css_file"];
		echo getFileContent(ew_DomainUrl()."/css/custom/".$css, FILE_USE_INCLUDE_PATH);
		$rs->MoveNext();
	}
}


function reloadAuthoringTemplate($contentId)
{

	global $portalId;
	$sSql="Select portal_authoringtemplate_elements.id as elementId,   portal_authoringelement.id as id
From portal_content Inner Join
  portal_authoringtemplate_elements On
    portal_authoringtemplate_elements.authoringId =
    portal_content.authoringtemplateId Inner Join
  portal_authoringelement On portal_authoringelement.id =
    portal_authoringtemplate_elements.elementId
Where portal_content.id = ".$contentId."
Group By portal_authoringtemplate_elements.name,
  portal_authoringtemplate_elements.elementId,
  portal_authoringelement.id
Having portal_authoringtemplate_elements.name Not In (Select
    portal_authoringtemplate_elements.name
  From portal_content Inner Join portal_contentvalues On portal_content.id =
      portal_contentvalues.contentId Inner Join
      portal_authoringtemplate_elements On
      portal_contentvalues.authoringtemplate_elementId =
      portal_authoringtemplate_elements.id Where portal_content.id = ".$contentId.") ";
    Portal_log($sSql);
//echo $sSql;

    $GLOBALS["conn"]->BeginTrans();
    $rs=$GLOBALS["conn"]->Execute($sSql);
    $changed=false;
    while ($rs!=null && !$rs->EOF)  {


        $id=$rs->fields["id"];
        $elementId=$rs->fields["elementId"];

        $sSql="INSERT IGNORE INTO `portal_contentvalues` (`id`, `contentId`, `authoringtemplate_elementId`, `authoringelementId`,`portalId`) VALUES (NULL, '".$contentId."', '".$elementId."',  '".$id."',$portalId);";
        Portal_log($sSql);
        $rs2=$GLOBALS["conn"]->Execute($sSql);

        $rs->MoveNext();
        $changed=true;
    }
    $GLOBALS["conn"]->CommitTrans();


/*
    $sSql="Select portal_authoringtemplate_elements.id as elementId,   portal_authoringelement.id as id
From portal_content Inner Join
  portal_authoringtemplate_elements On
    portal_authoringtemplate_elements.authoringId =
    portal_content.authoringtemplateId Inner Join
  portal_authoringelement On portal_authoringelement.id =
    portal_authoringtemplate_elements.elementId
Where portal_content.id = ".$contentId."
Group By portal_authoringtemplate_elements.name,
  portal_authoringtemplate_elements.elementId,
  portal_authoringelement.id
Having portal_authoringtemplate_elements.name  In (Select
    portal_authoringtemplate_elements.name
  From portal_content Inner Join portal_contentvalues On portal_content.id =
      portal_contentvalues.contentId Inner Join
      portal_authoringtemplate_elements On
      portal_contentvalues.authoringtemplate_elementId =
      portal_authoringtemplate_elements.id Where portal_content.id = ".$contentId.") ";
    Portal_log($sSql);
    //echo $sSql;
    $rs=$GLOBALS["conn"]->Execute($sSql);

    while ( !$rs->EOF)  {


        $id=$rs->fields["id"];
        $elementId=$rs->fields["elementId"];

        $sSql="Delete from `portal_contentvalues`where `contentId`=$contentId and  `authoringelementId`=$id ";
        Portal_log($sSql);
        $rs2=$GLOBALS["conn"]->Execute($sSql);

        $rs->MoveNext();
        //$changed=true;
    }*/

	if ($changed)
	{

		//if (!EW_DEBUG_ENABLED) echo "<script>window.location='".ew_ScriptName()."?id=".$contentId."';</script>";
		redirect("?");

	}

    /*
     *
     SELECT
portal_authoringtemplate_elements.id,
portal_authoringtemplate_elements.`name`
FROM
portal_content
INNER JOIN portal_contentvalues ON portal_contentvalues.contentId = portal_content.id
INNER JOIN portal_authoringtemplate_elements ON portal_contentvalues.authoringtemplate_elementId = portal_authoringtemplate_elements.id
Where portal_content.id = 660 HAVING portal_authoringtemplate_elements.`name` Not in (SELECT
portal_authoringtemplate_elements.`name`
FROM
portal_authoringtemplate_elements
INNER JOIN portal_content ON portal_content.authoringtemplateId = portal_authoringtemplate_elements.authoringId
WHERE
portal_content.id = 660)
     */


}
function getCurrentUserLevel()
{
	global $portalId;
	$groups=getUserGroupsById(getCurrentUserId());
	
	if (in_array(getObjByKey("portal_groups","id","name","SuperAdministrator","portalId",$portalId), $groups))
	{
	
	
	return -1;
	}
	return null;
	global $currentUserLevel,$portalId;

	if (!isset($currentUserLevel) || $currentUserLevel==null || $currentUserLevel=="") {
		if (CurrentUserName()=="Administrator") {$currentUserLevel=-1;
	}else{
			$sSql="Select userLevel From portal_logins Where login = '".CurrentUserName()."' And portalId=".$portalId;
			Portal_log($sSql);
			//echo $sSql;
			$rs=$GLOBALS["conn"]->Execute($sSql);
			while ( !$rs->EOF)  {

				$currentUserLevel=$rs->fields["userLevel"];

				$rs->MoveNext();
			}
		}

	}
	return $currentUserLevel;
}

function setupPayments()
{
	global $portalId;
	//Select portal.addDate From portal Where portal.id = 2
	$sSql="Select UNIX_TIMESTAMP(portal.addDate) as date From portal Where portal.id = ".$portalId;
	Portal_log($sSql);
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$stamp=$rs->fields["date"];

	//echo $date;
	//$stamp=strtotime($date." 00:00");
	$startYear=date("Y", $stamp);
	$startMonth=date("m", $stamp)+0;
	// echo $startMonth;
	$currentYear=date("Y");
	$currentMonth=date("m")+0;
	$i=$startYear;
	while($i<$currentYear+1)
	{


		if ($i==$startYear) $j=$startMonth; else $j=1;
		if ($i==$currentYear) $maxMonth=$currentMonth; else $maxMonth=12;
		while($j<=$maxMonth)
		{
			//echo $i." / ".$j." <br/>";
			$date=date("Y-m-d",mktime(0, 0, 0, $j  , 1, $i));
			$sSql="INSERT INTO payment_details VALUES (NULL,'".$portalId."','".$date."','N')";
			$GLOBALS["conn"]->Execute($sSql);
			//echo $sSql."<br/>";
	 	$j++;
		}
		$i++;
	}

}


function  copyright()
{

	?>
	<div id="poweredby"><img src="/images/poweredby.png"/></div>
	<?php

}

function isPaid()
{
	global $portalId;
	$sSql="Select Count(Distinct payment_details.id) as cnt
From payment_details
Where payment_details.paid = 'N' And payment_details.portalId = ".$portalId;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$npaid=$rs->fields["cnt"]+0;
	if ($npaid>=3) return false;
	return true;
}


function Dispaly_Page_Msg($msg)
{
	?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	<title>Butterfly Portal</title>
	<style>
	body{
	margin: auto; width: 100%;
	   text-align: center;
	}
	</style>
	</head>
	<body>
	<a href="http://www.butterfly-portal.net" title="Butterfly Portal"><?php echo $msg; ?></a>
	</body>
	   </html>

	   <?php

}

function getAvailableLanguages()
{
	global $portalId,$lang;


$sSql="Select portal_languages.lib,
  portal_languages.value
From portal_portal_languages Inner Join
  portal_languages On portal_portal_languages.languageId = portal_languages.id
Where portal_portal_languages.portalId =$portalId and portal_languages.value!='".$lang."'";


	Portal_log($sSql);
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);

	if ($rs && $rs->RecordCount()>0) {
	?>
	<div class="lang">
	<?php
    $cururi=preg_replace("#".$lang."/#","",curPageURI());
	while ( !$rs->EOF)  {

	 	$_lang=$rs->fields["value"];
        $url=createRelativeUrl("language",$_lang);
        $url="/".$_lang.$cururi;
        if (strpos($url,"/portal")===false)
        $url=createNiceUrl("",$_lang,"pageName",getParameter("pageName"));

       // echo stripos(curPageURI(),".html");
        if (stripos(curPageURI(),".html")) {

            $url= str_replace("/".$lang."/","/",curPageURI());
        $url="/".$_lang.$url;

        }
	 	?>

	 	<a href="<?php echo $url; ?>"><img title="<?php echo $rs->fields["lib"]; ?>" src="/images/flags/flag_<?php echo $rs->fields["value"]; ?>.png"/></a>&nbsp;

	 	<?php

		$rs->MoveNext();
	}
	?>
		</div>

		<?php
        $sSql="Select portal_languages.lib,
  portal_languages.value
From portal_portal_languages Inner Join
  portal_languages On portal_portal_languages.languageId = portal_languages.id
Where portal_portal_languages.portalId =".$portalId." and portal_languages.value='".$lang."'";
        $rs=$GLOBALS["conn"]->Execute($sSql);
        if ($rs->RecordCount()==0) {

            header("location: ".createRelativeUrl("language",$_lang));
        }



	}
}

function rand_string( $length ) {
	$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	$str="";
	$size = strlen( $chars );
	for( $i = 0; $i < $length; $i++ ) {
		$str .= $chars[ rand( 0, $size - 1 ) ];
	}

	return $str;
}
function getSubCategories($categoryId)
{
    $ids=$categoryId.",";
    $sql = "SELECT * FROM shop_category WHERE parentCategoryId=$categoryId";
    // echo $sql;
    $rs = ew_LoadRecordset($sql);


    while(!$rs->EOF){


        $ids.=getSubCategories($rs->fields["id"]);
        $rs->MoveNext();
    };
    return $ids;
}

function doNotCache($first)
{
	if ($first) echo  "?"; else echo "&";
	echo "t=".$_SERVER['REQUEST_TIME']."".rand_string(4);
}


function getTimestamp()
{
	return $_SERVER['REQUEST_TIME']."_".rand_string(4);
}
//
$SQLKEYWORDS=array("INSERT INTO","SELECT ","DROP","DELETE FROM","CREATE");

function setParameter($var,$value)
{
	
	$_REQUEST[$var]=$value;
}

function getParameter($var)
{
	global $SQLKEYWORDS;
	// for security proposes
	//echo count($SQLKEYWORDS);
	if (!isset($_REQUEST[$var])) return null;
	
	//do a specific treatment to an array
	
	if (is_array($_REQUEST[$var])) return $_REQUEST[$var];
	
	$i=0;
	while ($i<count($SQLKEYWORDS)){
	if (stripos($_REQUEST[$var],$SQLKEYWORDS[$i])!=false) {

        echo "This script is protected against SQL Injection"."<br/>";
    }
	$i++;
	}

    if (!isLocal()) return $_REQUEST[$var];
	return mysql_real_escape_string($_REQUEST[$var]);

}

function getSession($var) {
	if (isset($_SESSION[$var])) return $_SESSION[$var];
	return null;
}


function countDays($debut, $fin) {
    $tDeb = explode("-", $debut);
    $tFin = explode("-", $fin);
    
$diff = mktime(0, 0, 0, $tFin[1], $tFin[2], $tFin[0]) - mktime(0, 0, 0, $tDeb[1], $tDeb[2], $tDeb[0]);
return(($diff / 86400)+1);
}

function addCnameAlias($alias)
{



	require_once('sitelutions.class.php');

	$sl = new SitelutionsDNS('mohamed.zeouine@gmail.com', 'klawi0', 'https://api.sitelutions.com/soap-api','https://api.sitelutions.com/API');

	$x=$sl->listDomains();
	tableout($x);
	foreach ($x as $domain){
		$y=$sl->listRRsByDomain($domain['id']);
		echo '<h3>'.$domain['name'].'</h3>';
		tableout($y);
	}
	/*

	echo "getDomainByName";
	tableout(array($sl->getDomainByName('YOURDOMAINNAME.TLD')));

	echo "getDomainByID";
	tableout(array($sl->getDomainByID(12345)));

	$hostname='YOURHOSTNAME';
	echo "ADDing RR $hostname";
	$newrrid=$sl->addRR(12345, "1.1.1.1", 'a', $hostname, null, null);

	echo "getRRbyID - added in last test added";
	tableout(array($sl->getRRByID($newrrid)));

	echo "updateDomain - change ttl";
	$sl->updateDomain(12345, null, null, null, null, null, null, null, null, null, rand(28000,900000));
	tableout(array($sl->getDomainByID(12345)));

	echo "addDomain - displayed below";
	$newdomainid=$sl->addDomain ('testdomain'.rand().".net");
	tableout(array($sl->getDomainByID($newdomainid)));

	echo "updateRR - recently added RR; random ttl";
	$sl->updateRR($newrrid, rand(28000,90000));

	echo "getRRByID - redently added RR";
	tableout(array($sl->getRRByID($newrrid)));

	echo "deleteRR - deleting recently added RR";
	$sl->deleteRR($newrrid);

	echo "deleteDomain - recently added domain";
	$sl->deleteDomain($newdomainid, true);

	function tableout($arr){
		if (count($arr) < 1 OR !is_array($arr) or !is_array($arr[0])) return "";

		echo "<table border=1><tr>\n";
		foreach ($arr[0] AS $name=>$val){
			echo "<th>".ucwords($name)."</th>";
		}
		echo "</tr>\n";
		foreach ($arr AS $record){
			echo "<tr>\n";
			foreach ($record AS $name=>$val){
				echo "<td>$val</td>";
			}
			echo "</tr>\n";
		}
			echo "</table>\n";
	*/


}

function stripAccents($string){
$string=str_replace("ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©", "e", $string);
$string=str_replace("ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¨", "e", $string);
$string=str_replace("ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Âª", "e", $string);
$string=str_replace("ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â ", "a", $string);
$string=str_replace("ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â§", "c", $string);
return $string;
}
function createUrl()
{
	$curPageUri="/";
	//$pageUrl=str_replace("//", "/", $pageUrl);
	if (strpos($curPageUri,"?")!=false) $separator="&"; else $separator="?";
	//if (strpos($curPageUri,"?")) $separator="&"; else  $separator="?";
	$a = func_get_args();
	for( $t=0;$t<count($a);  ) {
	//	$pageUrl.=addParameter($a[$t++],$a[$t++]);
	$param=$a[$t++];
	$value=$a[$t++];
		if (strpos($curPageUri,"&".$param."=")) {
				$curPageUri=str_replace("&".$param."=".$_REQUEST[$param],"&".$param."=".$value,$curPageUri);
		}elseif (strpos($curPageUri,"?".$param."=")) {

			$curPageUri=str_replace("?".$param."=".$_REQUEST[$param],"?".$param."=".$value,$curPageUri);
		}else{
			$curPageUri.=$separator.$param."=".$value;
			$separator="&";
		}
		/*echo $separator.$a[$t++]."=".$a[$t++];
		$separator="&";
		*/
	}
	return $curPageUri;
}


function createRelativeUrl()
{
    $curPageUri=curPageURI();
    //$pageUrl=str_replace("//", "/", $pageUrl);
    if (strpos($curPageUri,"?")!=false) $separator="&"; else $separator="?";
    //if (strpos($curPageUri,"?")) $separator="&"; else  $separator="?";
    $a = func_get_args();
    for( $t=0;$t<count($a);  ) {
        //	$pageUrl.=addParameter($a[$t++],$a[$t++]);
        $param=$a[$t++];
        $value=$a[$t++];
        if (strpos($curPageUri,"&".$param."=")) {
            $curPageUri=str_replace("&".$param."=".$_REQUEST[$param],"&".$param."=".$value,$curPageUri);
        }elseif (strpos($curPageUri,"?".$param."=")) {

            $curPageUri=str_replace("?".$param."=".$_REQUEST[$param],"?".$param."=".$value,$curPageUri);
        }else{
            $curPageUri.=$separator.$param."=".$value;
            $separator="&";
        }
        /*echo $separator.$a[$t++]."=".$a[$t++];
          $separator="&";
          */
    }
    return $curPageUri;
}

function setParameterInSession($param)
{
    $_SESSION[$param]=getParameter($param);
}

function setInSession($param,$value)
{
	$_SESSION[$param]=$value;
}




function getParameterFromSession($param)
{
	if (!isset($_SESSION[$param])) return null;
    return $_SESSION[$param];
}


function getPageLayout($pageId){
global $portalId;
	$sSql ="SELECT layout.layout FROM  portal_layout layout INNER JOIN  portal_pages pages ON pages.layoutId = layout.id WHERE pages.id='".$pageId."' AND pages.portalId =".$portalId."";
	$rs=$GLOBALS["conn"]->Execute($sSql);  Portal_log($sSql);
	$layout=$rs->fields["layout"];

	return str_replace("\"","\\\"",$layout);
}


function loadfilter($filtername,$filterValue)
{
	

	
	if (getParameterFromSession($filtername)!=$filterValue)
	{
	
		setInSession($filtername,$filterValue);
	
		header("refresh: 0;");
	}
}

function createNiceUrl()
{



    $curPageUri="/";
    //$pageUrl=str_replace("//", "/", $pageUrl);
    if (strpos($curPageUri,"?")!=false) $separator="&"; else $separator="?";
    //if (strpos($curPageUri,"?")) $separator="&"; else  $separator="?";
    $a = func_get_args();
    for( $t=0;$t<count($a);  ) {
        //	$pageUrl.=addParameter($a[$t++],$a[$t++]);
        $param=$a[$t++];
        $value=$a[$t++];
        if (strpos($curPageUri,"&".$param."=")) {

            $curPageUri=str_replace("&".$param."=".$_REQUEST[$param],"&".$param."=".$value,$curPageUri);

        }elseif (strpos($curPageUri,"?".$param."=")) {

            $curPageUri=str_replace("?".$param."=".$_REQUEST[$param],"?".$param."=".$value,$curPageUri);
        }else{
            $curPageUri.=$separator.$param."=".$value;
            $separator="&";
        }
        /*echo $separator.$a[$t++]."=".$a[$t++];
          $separator="&";
          */
    }

   if (strpos($curPageUri,"?pageName="))
    {
            $curPageUri=str_replace("?pageName=","",$curPageUri);
        }

    $curPageUri=str_replace("&","/",$curPageUri);
    $curPageUri=str_replace("=","-",$curPageUri);
    $curPageUri=str_replace("/-","/",$curPageUri);
    $curPageUri=str_replace("?-","",$curPageUri);
    $curPageUri=str_replace("pageName-","",$curPageUri);
    $curPageUri.=".html";
    return $curPageUri;
}

    function createCleanUrl()
{

	$curPageUri="";
	//$pageUrl=str_replace("//", "/", $pageUrl);
	if (strpos($curPageUri,"?")!=false) $separator="&"; else $separator="?";
	//if (strpos($curPageUri,"?")) $separator="&"; else  $separator="?";
	$a = func_get_args();
	for( $t=0;$t<count($a);  ) {
		//	$pageUrl.=addParameter($a[$t++],$a[$t++]);
		$param=$a[$t++];
		$value=$a[$t++];
		if (strpos($curPageUri,"&".$param."=")) {
			$curPageUri=str_replace("&".$param."=".$_REQUEST[$param],"&".$param."=".$value,$curPageUri);
		}elseif (strpos($curPageUri,"?".$param."=")) {

			$curPageUri=str_replace("?".$param."=".$_REQUEST[$param],"?".$param."=".$value,$curPageUri);
		}else{
			$curPageUri.=$separator.$param."=".$value;
			$separator="&";
		}
		/*echo $separator.$a[$t++]."=".$a[$t++];
			$separator="&";
		*/
	}
	return $curPageUri;
}


function encryptUrl($url)
{

	return TEAencrypt($url, KEY);
}

function fixBarCode($barCode){

    if (is_numeric($barCode))   return $barCode;

        $codes=array("ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â ","&","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©","\"","'","(","-","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¨","_","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â§");
  $barCode=strtolower($barCode);

        $array = str_split($barCode);
   // if (ord($array[0])<=)
        $tmpbarCode="";
        foreach($array as $char) {
           echo $char." ".ord($char). "<br/>";
            /* now you do whatever you like with every character of your string */
            /* the following code converts your email address into dec entities */
        $i=0;
            foreach($codes as $code)
            {
               // echo ord($char)." ".ord($code)."<br/>";
                if (ord($char)==ord($code)) {
                    $tmpbarCode.= $i;
                   break;
                }
                $i++;

            }


                //array_search($char,array_keys($codes));
        }
if ($tmpbarCode=="") $tmpbarCode=$barCode;

    return $tmpbarCode;
}


function decryptUrl($url)
{

	return TEAdecrypt($url, KEY);
}

function encryptString($str)
{

    return TEAencrypt($str, KEY);
}

function decryptString($str)
{

    return TEAdecrypt($str, KEY);
}

function checkDuplicates()
{
	$a = func_get_args();
	$table=$a[0];
	$sSql="SELECT * FROM $table WHERE";
	for( $t=1;$t<count($a);  ) {
	//	$pageUrl.=addParameter($a[$t++],$a[$t++]);
	$param=$a[$t++];
	$value=$a[$t++];
	$sSql.=" $param='$value' and ";
	}

	$sSql.=" 1=1 ";

	//echo $sSql.."<br/>";

	$rs=$GLOBALS["conn"]->Execute($sSql);
	if ($rs && $rs->RecordCount()>0) {
		return true;
	}
	return false;
}



function getFirstWorkflowStage($workflowId)
{

	$sSql="Select portal_workflow_stage.id
From portal_workflow Inner Join
  portal_workflow_stage On portal_workflow.id = portal_workflow_stage.workflowId
Where portal_workflow.id = ".$workflowId."
Order By portal_workflow_stage.orderCmpnt";

	$rs=$GLOBALS["conn"]->Execute($sSql);

	return $rs->fields["id"];

}


function nextWorkflowStage($id,$workflowId,$stageId,$target)
{

	$sSql="Select *
From portal_workflow_stage
Where portal_workflow_stage.workflowId = ".$workflowId." And
  portal_workflow_stage.id > ".$stageId."
Order By portal_workflow_stage.orderCmpnt   ";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$nextWorkflowStageId=$rs->fields["id"];

	//echo $sSql;
	if ($nextWorkflowStageId!=""){

		//check if the user has the abilty to perform this task

		
		if (canView("portal_workflow_stage", $nextWorkflowStageId)){


	$sSql="UPDATE  `".$target."` SET  `workflow_stageId` =  '".$nextWorkflowStageId."',`workflow_statusId` =  '".getWorkflowStatusId($nextWorkflowStageId)."' WHERE  `".$target."`.`id` =".$id;
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	setParameter("succes","Succesfully moved to the next stage.");

}
	else{

	setParameter("error","You don't have the required credentials to perform this task !");
	}
	}else{


	setParameter("error","There is no more stages in the current workflow !");
	}

}



function restartWorkflow($id,$workflowId,$target)
{
	$sSql="Select *
From portal_workflow_stage
Where portal_workflow_stage.workflowId = ".$workflowId."
Order By portal_workflow_stage.orderCmpnt ";

	//echo $sSql."<br/>";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$nextWorkflowStageId=$rs->fields["id"];
	if ($nextWorkflowStageId!=""){


if (canView("portal_workflow_stage", $nextWorkflowStageId)){



			$sSql="UPDATE  `".$target."` SET  `workflow_stageId` =  '".$nextWorkflowStageId."',`workflow_statusId` =  '".getWorkflowStatusId($nextWorkflowStageId)."' WHERE  `".$target."`.`id` =".$id;
			$rs=$GLOBALS["conn"]->Execute($sSql);
			setParameter("succes","Workflow Succesfully restarted.");
		}
		else{

			setParameter("error","You don't have the required credentials to perform this task !");
			//ShowError("You don't have the required credentials to perform this task !");
		//	register_shutdown_function('ShowError',"You don't have the required credentials to perform this task !");
			//register_shutdown_function('SystemInfo',"You don't have the required credentials to perform this task !");
			//SystemInfo("You don't have the required credentials to perform this task ! ");

		}
	}

}

function getWorkflowStatusId($nextWorkflowStageId){


	$sSql="Select portal_workflow_stage.workflow_statusId As id
From portal_workflow_stage
Where portal_workflow_stage.id = ".$nextWorkflowStageId;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["id"];

}



function applyWorkflow($workflowId,$authoringId)
{
	if ($workflowId!=""){


	$sSql="Select *
	From portal_workflow_stage
	Where portal_workflow_stage.workflowId = ".$workflowId."
	Order By portal_workflow_stage.orderCmpnt ";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$nextWorkflowStageId=$rs->fields["id"];

	if (canView("portal_workflow_stage", $nextWorkflowStageId)){
	$sSql="UPDATE portal_content SET `workflowId`=".$workflowId.", `workflow_stageId`=".$nextWorkflowStageId.",`workflow_statusId` =  '".getWorkflowStatusId($nextWorkflowStageId)."' Where portal_content.authoringtemplateId = ".$authoringId." And ISNULL(portal_content.workflowId)";
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	setParameter("succes","Workflow Succesfully Set.");
	sendNotificationMail("");
	}else{

			setParameter("error","You don't have the required credentials to perform this task !");
		}
	
	
	}
}

function sendNotificationMail($msg)
{

}

function applyWorkflowtoObject($workflowId,$objectId,$target)
{
	$sSql="Select *
	From portal_workflow_stage
	Where portal_workflow_stage.workflowId = ".$workflowId."
	Order By portal_workflow_stage.orderCmpnt ";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$nextWorkflowStageId=$rs->fields["id"];


	if ($nextWorkflowStageId!=""){



	if (canView("portal_workflow_stage", $nextWorkflowStageId)){

			$sSql="UPDATE ".$target." SET `workflowId`=".$workflowId.", `workflow_stageId`=".$nextWorkflowStageId." Where id=".$objectId;
			$rs=$GLOBALS["conn"]->Execute($sSql);
			setParameter("succes","Workflow Succesfully Set.");
		}
		else{

			setParameter("error","You don't have the required credentials to perform this task !");
		}
	}



}




function getWorkflowId($authoringId)
{
	$sSql="Select portal_authoringtemplate.workflowId
From portal_authoringtemplate
Where portal_authoringtemplate.id = ".$authoringId;

	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["workflowId"];
}

function reApplyWorkflow($objectId,$authoringId,$target)
{

	applyWorkflowtoObject(getWorkflowId($authoringId),$objectId,$target);

}


function countProducts($categoryId)
{
    $count=0;


    if ($categoryId!=""){
    $count=getObjByKey("shop_articles","count(*)","categoryId",$categoryId);

    $sql = "SELECT * FROM shop_category WHERE parentCategoryId=$categoryId";

    $rs = ew_LoadRecordset($sql);


    while(!$rs->EOF){


        $count+=countProducts($rs->fields["id"]);
        $rs->MoveNext();
    };}
    return $count;
}

function ShowError($msg)
{
	?>
<div id="error" class="error">

<?php echo $msg; ?>

</div>
<?php

}

function ShowWarning($msg)
{
    ?>
<div id="warning" class="warning">

    <?php echo $msg; ?>

</div>
<?php

}

function ShowSuccess($msg)
{
	?>


	<div id="success" class="success">

<?php echo $msg; ?>

</div>

<?php

}



function SystemInfo($msg)
{
	?>
	<div id="error" class="error">
	<?php echo $msg; ?>
	</div>
	<script>

	$("#error").dialog({
		title: 'Error',
		autoOpen: true,
		height: 200,
		width: 600,
		modal: true,
		zIndex: 3999,
		buttons: {

		}
	});
	//$('#error').modal();
	</script>
	<?php
}

function setupForm()
{

	 foreach ( $_REQUEST as $key => $value )
	{
		if (stripos($key,"Portlet_")===false){
		?>

		<input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>" >
		<?php }

	}
}

function getLastId()
{
	$sSql ="SELECT last_insert_id() AS id";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	if (!$rs || $rs->EOF) return null;
	return $rs->fields["id"];

}

function getAuthoringElementTypeId($type)
{
	$sSql ="Select id
	From portal_authoringelement
		Where portal_authoringelement.name = '".$type."'";
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["id"];
}

function getAuthoringTemplateIdByContent($contentId,$targetportal=null)
{

	$sSql="SELECT portal_content.authoringtemplateId FROM portal_content where id=".$contentId;
if ($targetportal!=null) { $sSql=" And portalId=".$targetportal; }
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return  $rs->fields["authoringtemplateId"];

}

function addAuthoringElement($authoringId,$name,$type){


	$sSql="INSERT INTO `portal_authoringtemplate_elements` (`id` ,`authoringId` ,`elementId` ,`name`) VALUES (NULL , '$authoringId', '".getAuthoringElementTypeId($type)."', '".$name."')";
	$rs=$GLOBALS["conn"]->Execute($sSql);

}

function addPortlet($pageId,$portletId,$container){
    global $portalId;
    $GLOBALS["conn"]->BeginTrans();
	$sSql ="INSERT INTO portal_portletpage (id ,pageId ,portletId ,place,orderCmpnt,portalId ) VALUES ( NULL , '".$pageId."', '".$portletId."', '".$container."','".getMaxOrderPortletInContainer($pageId,$container)."',$portalId); ";
	//echo  $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);

    $GLOBALS["conn"]->CommitTrans();

	return getLastId();
}


function getAppId($appname)
{

	$sSql="Select portal_app.id From portal_app Where portal_app.name = '".$appname."'   ";

	//echo  $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);

	return $rs->fields["id"];

}
function addApplication($appname,$portalId)
{
	$sSql="INSERT INTO `portal_dev`.`portal_portal_app` (`id` ,`portalId` ,`appId`) VALUES (NULL , '".$portalId."', '".getAppId($appname)."')";
	//echo $sSql."<br/>";
	$GLOBALS["conn"]->Execute($sSql);

}


function reloadPortletPreferences($coupleId){
    global $portalId;
	$sSql ="SELECT * FROM `portal_portlet_preferences` WHERE `portlet_page_id`=$coupleId;";
	//echo $sSql ;
	$rs=$GLOBALS["conn"]->Execute($sSql);

	$exclusion=array();

	while (!$rs->EOF)  {

		array_push($exclusion,$rs->fields["name"]);

		$rs->MoveNext();
	}



	$sSql ="Select portlet_preferences_names.name ".
"From portal_portlet portlet Inner Join ".
"portal_portlet_preferences_names portlet_preferences_names On portlet.id = portlet_preferences_names.portlet_id ".
"Inner Join ".
"portal_portletpage portletpage On portlet.id = portletpage.portletId ".
"Where portletpage.id = ".$coupleId;
//	echo $sSql ;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	$paramToNotDelete="(";
	while ( !$rs->EOF)  {
		$name=$rs->fields["name"];
       // echo $name;
       // print_r($exclusion);
		if (in_array($name,$exclusion)==false)
		{




			$sSql="INSERT INTO `portal_portlet_preferences` (`id` ,`portlet_page_id` ,`name` ,`value`,`portalId`) VALUES (NULL , '$coupleId', '$name', '','$portalId');";
		//	echo $sSql ."<br/>";

			$GLOBALS["conn"]->Execute($sSql);
		}
		$paramToNotDelete.=" `name`='".$name."' OR ";

		$rs->MoveNext();
	}
	$paramToNotDelete.=" 1=2 )";
	if( $paramToNotDelete!="( 1=2 )" )	{
		$sSql="DELETE FROM `portal_portlet_preferences` WHERE `portlet_page_id`=".$coupleId." and not ".$paramToNotDelete;
		//echo $sSql ."<br/>";
		$GLOBALS["conn"]->Execute($sSql);
	}

}

function savePortletPreferences($coupleId,$value,$name)
{
    $sSql = "UPDATE `portal_portlet_preferences` SET `value` = '$value' WHERE `portlet_page_id` =$coupleId and `name` = '$name';";
    //echo $sSql ;
    $GLOBALS["conn"]->Execute($sSql);
}


function deletePortal($url)
{
	if ($url=="omni-technologies") $url="";
	$sSql="Select portal.id From portal  Where portal.url = '".$url."'";
	$rs=$GLOBALS["conn"]->Execute($sSql);


	$sSql ="DELETE FROM `portal_pages` WHERE `portalId`=".$rs->fields["id"];
	//echo $sSql ;
	$GLOBALS["conn"]->Execute($sSql);
	/*
	$sSql ="DELETE FROM `portal_content` WHERE `portalId`=".$rs->fields["id"];
	echo $sSql ;
	$GLOBALS["conn"]->Execute($sSql);*/

	$sSql ="DELETE FROM `portal` WHERE `url`='".$url."' ;";
	//echo $sSql ;
	$GLOBALS["conn"]->Execute($sSql);

	if ($url!="") rrmdir("portalfiles/".$url);


}

function displayError($msg,$id)
{
	global $error;
	$error=true;
	?>
	<script type="text/javascript">
	$(function() {

	$("#<?php echo $id ?>_error").html("<?php echo $msg; ?>");


        $("#<?php echo $id ?>").addClass("validateerror");



    $("#<?php echo $id ?>").focus(function(){
      //  $(this).prev().hide();
        $(this).removeClass("validateerror");

    });
    });
	</script>
	<?php


}


function getFilesPath($name,$relative=true)
{
	if ($relative) $relative=""; else  $relative="/";
	$path=$relative."portalfiles/".getPortalUrl()."/".strtolower($name);

    //echo $path;
	return $path;
}

function getRFilesPath($name,$relative=true)
{
	
	$path="\\portalfiles\\".getPortalUrl()."\\".strtolower($name);

	//echo $path;
	return $path;
}



function getPageNameById($id)
{
	$sSql="Select name as name From portal_pages Where id=".$id;
	//	echo $sSql;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["name"];

}


function checkTable($table)
{
	

	
	$sSql="SHOW TABLES LIKE '$table'";
	//echo $sSql;
	$tables=$GLOBALS["conn"]->Execute($sSql);
	    if ($tables && 	$tables->RecordCount()>0 ) return true;
		return false ;
}
function getTableColumns($table)
{
	$tcolumns=array();
	if (checkTable($table)){
	
	$sSql="SHOW COLUMNS FROM `$table`";
	$columns=$GLOBALS["conn"]->Execute($sSql);
	


	while ($columns && !$columns->EOF)  {
		$name=$columns->fields["Field"];
		//$value=$rs->fields[$name];
	
		array_push($tcolumns, $name);
	
	
		$columns->MoveNext();
	}
	}
	return $tcolumns;
}

function export_module($module,$id,&$fp,&$rs)
{
	$sSql="Select * from portal_".$module." where id=".$id;
	$rs=$GLOBALS["conn"]->Execute($sSql);

	$sSql="SHOW COLUMNS FROM portal_".$module;
	$columns=$GLOBALS["conn"]->Execute($sSql);

	fputs($fp, "[".$module."/".$id."]\n");

	while ( !$columns->EOF)  {
		$name=$columns->fields["Field"];
		$value=$rs->fields[$name];

		if ($name=="portalId") $value="[current_portal]";
		elseif (endsWith($name,"Id")) {
			$value="[".substr($name, 0,strlen($name)-2)."/".$value."]";


		}
		if ($name!="id") fputcsv($fp, array($name,$value));


		$columns->MoveNext();
	}

}


function startsWith($haystack,$needle,$case=true) {
    if($case){return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);}
    return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
}

function endsWith($haystack,$needle,$case=true) {
    if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
    return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
}


function  getFileManagerImage($imageId)
{
	//$imageId="382";
	$sSql="Select filename From portal_file Where id=".$imageId;
		//echo $sSql;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	if ($rs)
	return getFilesPath("image",false)."/".$rs->fields["filename"];
	return "/images/notfound.png";
}

function redirect($url)
{
	header("Location: ".$url);
	
}


function smtpmailer($to, $from, $from_name, $subject, $body,$ccto=null) {
	global $error;
    global $app_portal_senderpwd;

	$mail = new PHPMailer();  // create a new object
	$mail->IsSMTP(); // enable SMTP
    $mail->IsMail();
	$mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
	if ($app_portal_senderpwd!="") $mail->SMTPAuth = true;  // authentication enabled
    global $app_portal_smtpssl;
    $mail->SMTPSecure = $app_portal_smtpssl; // secure transfer enabled REQUIRED for Gmail
    if ($app_portal_smtpssl=="no")  $mail->SMTPSecure=false;
	$mail->CharSet="utf-8";
	$mail->IsHTML(true);
    global $app_portal_smtphost;
    $mail->Host = $app_portal_smtphost;
    global $app_portal_smtpport;
    $mail->Port = $app_portal_smtpport;

    /*if (isLocal()) 	{
		$mail->Port = 465;
		$mail->SMTPSecure = 'ssl';
	}*/



    global $app_portal_sendermail;
    $mail->Username = $app_portal_sendermail;
    $mail->Password = $app_portal_senderpwd;
	$mail->SetFrom($from, $from_name);
	$mail->Subject = $subject;
	$mail->Body = "<span style='font-family: georgia,serif;'>".$body."</span>";
	if (strpos(";",$to))
	{
	$mail->AddAddress($to);
	}else{
		$to=explode(";", $to);
	foreach($to as $email)
	{
		$mail->AddAddress($email);
	}

	}
if ($ccto){
    if (strpos(";",$ccto))
    {

        $mail->AddBCC($ccto);
    }else{
        $ccto=explode(";", $ccto);
        foreach($ccto as $email)
        {
            $mail->AddBCC($email);
        }

    }}

	if(!$mail->Send()) {
		$error = 'Mail error: '.$mail->ErrorInfo;
     print_r(error_get_last(), true);
		return false;
	} else {
		$error = 'Message sent!';
		return true;
	}
}

function notifyAdmin_NewAccount(){
    global $app_portal_recivermail;

	if (getCurrentUserLevel()==2){
		register_shutdown_function('SystemInfo',"This account does not have sufficient right to edit the portal, a mail has been sent to the portal administrator in order to give you the adequate rights.");
	$user=CurrentUserName();

    $mails=$app_portal_recivermail;
	$body="Dear Admin<br/><br/>";
	$body.="A new user '".$user."' has been created and activated , but it still need to change his level to perform taks in the '".getPortalName()."' Portal.";
	$body.="<br/><br/><img src='http://www.omni-technologies.net/portal/images/poweredby.png'>";
	sendNotificationMail($body);
	
	}
}

function sendMailToAdmins($portalId,$msg)
{
	global $lang,$app_portal_sendermail,$app_portal_recivermail;
	$host=EW_PORTAL_URL;
	if (isLocal())  $host=getPortalUrl().".betasite.net";
	$host="http://".$host;
	
	
	
	//$_REQUEST["portalId"]=$portalId;
	$sSql = "SELECT mail FROM portal_logins WHERE userLevel <= 0 AND portalId = $portalId AND active = 1";

    //echo $sSql."<br/>";

	$rs = ew_LoadRecordset($sSql);
	$mails="";
	while ( !$rs->EOF)  {
		$mails.=$rs->fields["mail"].";";
	
		$rs->MoveNext();
	}

    $sSql = "SELECT mail FROM portal_logins WHERE userLevel = -1 AND portalId = $portalId AND active = 1";

    $rs = ew_LoadRecordset($sSql);
    $ccmails=null;
    if (!$rs || 	$rs->RecordCount()>0 ){
    $ccmails="";
    while ( !$rs->EOF)  {
        $ccmails.=$rs->fields["mail"].";";

        $rs->MoveNext();
    }
	$ccmails.=$app_portal_recivermail;
    }

   // echo $ccmails;
	/*$dear="Dear Admininstrator";
	if ($lang=="fr") $dear="Cher Admininstrateur";*/
    $dir="ltr";
    $style="font-family: Arial;font-size: 14px;";
    if ($lang=="ar") {
        $dir="rtl";
        $style="font-family: Microsoft Uighur;font-size: 24px;font-weight: normal;";
    }


	$body="<div style='$style' dir='$dir''>".$msg;
	$body.="<br/><br/><br/><a href='http://".EW_PORTAL_URL."'><img  src='http://".EW_PORTAL_URL."/".getPortalLogo()."'></a>";
	$body.="<br/><br/><a href='http://www.butterfly-portal.net/'><img width='50' src='http://www.butterfly-portal.net/portal/images/butterfly_gray.png'></a>";
    $body.="</div>";
    //<img width='50' src='http://www.omni-technologies.net/portal/images/omni_gray.png'>

   smtpmailer($mails, $app_portal_sendermail, getPortalName(), 'Notification', $body,$ccmails);

}


function getPortalLogo()
{
    global $lang,$portalId;
    $suffix="lt";
    if ($lang=="ar") $suffix="ar";
    $sSql="SELECT
portal_file.filename
FROM
portal
INNER JOIN portal_file ON portal.sitelogo_".$suffix."_file = portal_file.id
WHERE
portal.id = $portalId";
    $rs = ew_LoadRecordset($sSql);

return getFilesPath("image")."/".$rs->fields["filename"];

}
function sendMailTo($mail,$msg)
{
	global $app_portal_sendermail,$app_portal_recivermail,$lang;
	$host=EW_PORTAL_URL;
	if (isLocal())  $host=getPortalUrl().".betasite.net";
    $dir="ltr";
    if ($lang=="ar") $dir="rtl";
	$host="http://".$host;
    $body="<div dir='$dir''>".$msg;
    $body.="<br/><br/><br/><a href='http://".EW_PORTAL_URL."'><img  src='http://".EW_PORTAL_URL."/".getPortalLogo()."'></a>";
    $body.="<br/><br/><a href='http://www.butterfly-portal.net/'><img width='50' src='http://www.butterfly-portal.net/portal/images/butterfly_gray.png'></a>";
    $body.="</div>";
	smtpmailer($mail, $app_portal_sendermail, getPortalName(), 'Notification', $body);
//<img width='100' src='http://www.omni-technologies.net/portal/images/omni_gray.png'>
}

function exportContent()
{ 
	global $portalId;
	$sSql="";
	
	
	
	
}

function hideElement($id)
{
    ?>
<script type="text/javascript">

    $("#<?php echo $id; ?>").hide();
</script>

<?php

}


function rrmdir($dir) {
	if (is_dir($dir)) {
		$files = scandir($dir);
		foreach ($files as $file)
		if ($file != "." && $file != "..") rrmdir("$dir/$file");
		rmdir($dir);
	}
	else if (file_exists($dir)) unlink($dir);
}

function copyToUserFolder($fileName,$portalname){
	$structure = "portalfiles/".$portalname."/image/";
	ew_CreateFolder($structure);
	if (!copy("portal/images/".$fileName, $structure.$fileName)) {
		return FALSE;
	}
	return TRUE;
}

function addUserImage($fileName,$portalname,$portalId){
	
		if (!copyToUserFolder($fileName,$portalname)) return '';
		$sSql="INSERT INTO `portal_file` (`id` ,`addDate` ,`editDate` ,`portalId` ,`filename` ,`filetypeId`) VALUES (NULL ,  '".ew_CurrentDateTime()."',  '".ew_CurrentDateTime()."',  '".$portalId."',  '".$fileName."',  '2')";
		$GLOBALS["conn"]->Execute($sSql);
		return getLastId();
	}
	
function addPortalUser($username,$password,$mail,$portalId,$level,$active=0){
	
		$sSql="INSERT INTO `portal_logins` (`id` ,`login` ,`password` ,`mail` ,`active` ,`profile` ,`portalId` ,`userLevel` ,`addDate` ,`editDate`,`newUserLevel`)
	VALUES (NULL , '".$username."', '".encryptString($password)."', '".$mail."', ".$active.", '', '".$portalId."', ".$level.", '".ew_CurrentDateTime()."', '".ew_CurrentDateTime()."',".$level.")";
	
	//echo $sSql."<br/>";
	 $GLOBALS["conn"]->Execute($sSql);
	 
	 return getLastId();
	}

function removePortalUser($portalId,$login)
{
    if ($login!="" && $login!=null){
    removeObjByKey("portal_logins","portalId",$portalId,"login",$login,"active","0");
    }
}


function formError($id)
{

    /*	<span id="<?php echo $id?>_error" class="tooltip"></span>*/
	?>
<div class="formError" id="<?php echo $id?>_error"></div>


	<?php 
	
}


function CheckPassword($pwd)
{
	$score = 1;

	if (strlen($pwd) < 1)
	{
		return 0;
	}
	if (strlen($pwd) < 4)
	{
		return 1;
	}

	if (strlen($pwd) >= 8)
	{
		$score++;
	}
	if (strlen($pwd) >= 12)
	{
		$score++;
	}

	if (preg_match("/[a-z]/", $pwd) && preg_match("/[A-Z]/", $pwd))
	{
		$score++;
	}
	if (preg_match("/[0-9]/", $pwd))
	{
		$score++;
	}
	if (preg_match("/.[!,@,#,$,%,^,&,*,?,_,~,-,ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â£,(,)]/", $pwd))
	{
		$score++;
	}

	return $score;
}
function getPasswordScore($score)
{
	global $lang;
	$strength = array("Blank","Very Weak","Weak","Medium","Strong","Very Strong");
	if ($lang=="fr") $strength = array("Vide","TrÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©s faible","Faible","Moyen","Fort","TrÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©s Fort");
	return "(".$strength[$score]." !)";
	
}

function formText($fieldName,$size=0,$class=""){
	
	if ($size>0) $size="size=\"".$size."\""; else $size="";
	if ($class!="") $class="class=\"".$class."\"";
	?>


<input type="text" <?php echo $size; ?> <?php echo $class; ?> value="<?php echo getParameter($fieldName); ?>" name="<?php echo $fieldName; ?>" id="<?php echo $fieldName; ?>" />
<?php formError($fieldName); ?>

<?php
}


function formDate($fieldName,$class=""){

	if ($class!="") $class="class=\"".$class."\"";
	?>


<input type="text"  <?php echo $class; ?> value="<?php echo getParameter($fieldName); ?>" name="<?php echo $fieldName; ?>" id="<?php echo $fieldName; ?>" />
<?php formError($fieldName); ?>
<script>
$(function() {
	$( "#<?php echo $fieldName; ?>" ).datepicker();
});
</script>
<?php
}


function formTextArea($fieldName,$cols,$rows,$class=""){
	if ($class!="") $class="class=\"".$class."\"";
	?>


<textarea  name="<?php echo $fieldName; ?>" id="<?php echo $fieldName; ?>" <?php echo $class; ?> cols="<?php echo $cols; ?>" rows="<?php echo $rows; ?>" ><?php echo getParameter($fieldName); ?></textarea>
<?php formError($fieldName); ?>
<?php
}

function formPassword($fieldName,$size=0,$class=""){
	if ($size>0) $size="size=\"".$size."\""; else $size="";
	if ($class!="") $class="class=\"".$class."\"";
	?>

<input type="password" <?php echo $size; ?> <?php echo $class; ?> value="<?php echo getParameter($fieldName); ?>" name="<?php echo $fieldName; ?>" id="<?php echo $fieldName; ?>"/>
<?php formError($fieldName); ?>
<?php
}


function isActive($portalId){
	$sSql="SELECT active from portal where id=".$portalId;
	$rs=$GLOBALS["conn"]->Execute($sSql);

	if ($rs->fields["active"]=="N") return FALSE;
	return TRUE;
	
}

function activatePortal($portalId)
{
	$portal=new cportal();
	$rs["active"]="Y";
	$portal->CurrentFilter = "id=".$portalId;
	$GLOBALS["conn"]->Execute($portal->UpdateSQL($rs));
	register_shutdown_function("SystemInfo","Your portal has been succesfully activated.");
}


function getGoogleAnalyticsCode(){
	global $portalId, $googleAnalytics;
	
	if (isset($googleAnalytics)) return $googleAnalytics;
	
	$sSql ="Select * From portal  Where id = ".$portalId;
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	
	return $rs->fields["googleAnalytics"];
}

function getCountryId($country){
	
	$sSql ="Select id From portal_countries  Where lib_lt = '".$country."'";
	Portal_log($sSql);
	$rs=$GLOBALS["conn"]->Execute($sSql);
	
	return $rs->fields["id"];
	
}

function acivateUser($mail,$portalId=null)
{
	if ($portalId==null) global $portalId;
	$id=getObjByKey("portal_logins", "id", "mail", $mail,"portalId",$portalId);
	if (!$id) return null;
	$sSql="UPDATE portal_logins set active=1 where id=".$id;
	//echo $sSql;
	$GLOBALS["conn"]->Execute($sSql);
	return $id;
}

//shop
function getClientIdByMail($mail)
{
	if (!isset($mail) || $mail=="") return null;
	global $portalId;

	return getObjByKey("shop_clients","id","loginId",getObjByKey("portal_logins", "id", "mail", $mail,"portalId",$portalId));

}

function supprimePanier(){
	unset($_SESSION['panier']);
}



function creationPanier(){
	if (!isset($_SESSION['panier'])){
		$_SESSION['panier']=array();
		$_SESSION['panier']['unitId'] = array();
		$_SESSION['panier']['quantity'] = array();
		$_SESSION['panier']['size'] = array();
		$_SESSION['panier']['verrou'] = false;
	}
	return true;
}


function ajouterArticle($unitId,$quantity,$size){

	//Si le panier existe
	if (creationPanier() && !isVerrouille())
	{
		//Si le produit existe dÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©jÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â  on ajoute seulement la quantitÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©
		$positionProduit = array_search($unitId,  $_SESSION['panier']['unitId']);

		if ($positionProduit !== false)
		{
			$_SESSION['panier']['quantity'][$positionProduit] += $quantity ;
		}
		else
		{
			//Sinon on ajoute le produit
			array_push( $_SESSION['panier']['unitId'],$unitId);
			array_push( $_SESSION['panier']['quantity'],$quantity);
			array_push( $_SESSION['panier']['size'],$size);
		}
	}
	else
	echo "Un problÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¨me est survenu veuillez contacter l'administrateur du site.";
}



function supprimerArticle($unitId){
	//Si le panier existe
	if (creationPanier() && !isVerrouille())
	{
		//Nous allons passer par un panier temporaire
		$tmp=array();
		$tmp['unitId'] = array();
		$tmp['quantity'] = array();
		$tmp['size'] = array();
		$tmp['verrou'] = $_SESSION['panier']['verrou'];

		for($i = 0; $i < count($_SESSION['panier']['unitId']); $i++)
		{
			if ($_SESSION['panier']['unitId'][$i] !== $unitId)
			{
				array_push( $tmp['unitId'],$_SESSION['panier']['unitId'][$i]);
				array_push( $tmp['quantity'],$_SESSION['panier']['quantity'][$i]);
				array_push( $tmp['size'],$_SESSION['panier']['size'][$i]);
			}

		}
		//On remplace le panier en session par notre panier temporaire ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â  jour
		$_SESSION['panier'] =  $tmp;
		//On efface notre panier temporaire
		unset($tmp);
	}
	else
	echo "Un problÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¨me est survenu veuillez contacter l'administrateur du site.";
}



function modifierQTeArticle($unitId,$quantity){
	//Si le panier ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©xiste
	if (creationPanier() && !isVerrouille())
	{
		//Si la quantitÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â© est positive on modifie sinon on supprime l'article
		if ($quantity > 0)
		{
			//Recharche du produit dans le panier
			$positionProduit = array_search($unitId,  $_SESSION['panier']['unitId']);

			if ($positionProduit !== false)
			{
				$_SESSION['panier']['quantity'][$positionProduit] = $quantity ;
			}
		}
		else
		supprimerArticle($unitId);
	}
	else
	echo "Un problÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¨me est survenu veuillez contacter l'administrateur du site.";
}


function isVerrouille(){
	if (isset($_SESSION['panier']) && $_SESSION['panier']['verrou'])
	return true;
	else
	return false;
}



function getcartCount()
{
	if (isset($_SESSION['panier']))
	return count($_SESSION['panier']['unitId']);
	else
	return 0;

}

function getStatusByCode($code)
{
	global $LANG;
	
	$sSql = "SELECT status_".$LANG." as status FROM shop_orderstatus WHERE code=".$code;
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["status"];
}

function getStatusIdByCode($code)
{

	$sSql = "SELECT id FROM shop_orderstatus WHERE code='".$code."'";
//	echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["id"];
}

function getSizeIdByUnitId($unitId)
{

	$sSql = "SELECT shop_unit.size as id FROM shop_unit where id=".$unitId;
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["id"];
}

function getArticleIdByUnitId($unitId)
{

	$sSql = "SELECT shop_unit.articleId as id FROM shop_unit where id=".$unitId;
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["id"];
}


function getDefaultPictureByUnitId($unitId)
{

	$sSql = "SELECT
	shop_gallery.id
FROM
shop_unit
INNER JOIN shop_gallery ON shop_unit.articleId = shop_gallery.articleId
WHERE
shop_gallery.`default` = 'Y' AND
shop_unit.id = ".$unitId;
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["id"];
}


function getUserFullname($mail="")
{

	
	if (!isset($_SESSION["login"]) && $mail=="")
	{
		return  "";
	}
	
	if ($mail=="") $mail=$_SESSION["login"];

   // echo $mail;
	$sSql = "SELECT firstname, lastname FROM shop_clients where id=".getClientIdByMail($mail);
  //  echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return ucwords($rs->fields["firstname"])." ".ucwords($rs->fields["lastname"]);
	
}

function getUserPassword($mail="")
{
	
	global $portalId;
	
	if (!isset($_SESSION["login"]) && $mail=="")
	{
		return  "";
	}
	
	if ($mail=="") $mail=$_SESSION["login"];
	
	

	return getObjByKey("portal_logins","password","mail",$mail,"portalId",$portalId);
}

function getUserCompany()
{

$id=getShopClientId();

	if ($id==null)
	{
		return  "None";
	}


	$sSql = "SELECT company FROM shop_clients where  id=$id";
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	return $rs->fields["company"];

}

function getShopClientId()
{
    global $portalId;


    if (!isset($_SESSION["portal_status_UserName"]))
    {
        return null;
    }
    return getObjByKey("shop_clients","id","portalId",$portalId,"loginId",getObjByKey("portal_logins","id","login",$_SESSION["portal_status_UserName"],"portalId",$portalId));
}

function portalLogin($login,$password=null,$redirectUrl=null)
{

    global $Security ,$portalId;

  
    // Setup variables
         if (strpos($login,"@")!==false)   $username = getObjByKey("portal_logins","login","mail",ew_StripSlashes(@$login),"portalId",$portalId);
         else $username=$login;



         //is active
         if (getObjByKey("portal_logins","active","login",$username,"portalId",$portalId)=="0")  {return false;}

        
               return   $Security->ValidateUser($username, $password, FALSE); // Manual login
}


function isAccountActive()
{
global $portalId;
	if (getObjByKey("portal_logins","active","login",$_SESSION["portal_status_UserName"],"portalId",$portalId)==1) return true;
	return false;
	
}


function getPromos($clienId){

	$sSql = "SELECT promo FROM shop_clients where id=".$clienId;
	//echo $sSql;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	if ($rs && $rs->fields["promo"]>0)
	{
		return $rs->fields["promo"];

	}
	return 0;
}


function letters2numbers($s) 
 { 
 	$r='';
  for($i=0;$i<strlen($s);$i++) 
  { 
   if ((96 < ord($s[$i])) && (ord($s[$i]) < 123)) 
   { 
    $r .= ++$c; 
   } 
   else 
   { 
    $r .= $s[$i]; 
    $c = 0; 
   } 
  } 
  return $r; 
 } 
 
 
 function getArticleBarCode($articleId){
 
 	
 	$sSql="SELECT shop_articles.outDate, shop_articles.reference FROM shop_articles WHERE id= ".$articleId;
 
 	$rs=$GLOBALS["conn"]->Execute($sSql);
 
 
 
 	return substr($rs->fields["reference"],-4,4).str_replace("-", "", $rs->fields["outDate"]);
 }
 

function getBarCode($unitId){
	

	
	$sSql="SELECT shop_articles.outDate, shop_sizes.size, shop_articles.reference FROM shop_unit 
	INNER JOIN shop_articles ON shop_articles.id = shop_unit.articleId 
	INNER JOIN shop_sizes ON shop_unit.size = shop_sizes.id WHERE shop_unit.id= ".$unitId;
	
	$rs=$GLOBALS["conn"]->Execute($sSql);
	
	
	
	return substr($rs->fields["reference"],-2,2).str_replace("-", "", $rs->fields["outDate"]).$rs->fields["size"];
}

function getShopOrderStatusObj($id,$object)
{
	
	$sSql="SELECT shop_orderstatus.`".$object."` as object FROM shop_orderstatus WHERE shop_orderstatus.id=".$id;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	
	return $rs->fields["object"];
	
}



function getShopClientObjByOrderId($id,$object) {
	
		$sSql="SELECT shop_clients.".$object." as object FROM shop_order INNER JOIN shop_clients ON shop_order.clientId = shop_clients.id WHERE shop_order.id=".$id;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	
	return $rs->fields["object"];
}


function getShopOrderObj($id,$object) {

	$sSql="SELECT shop_order.".$object." as object FROM shop_order WHERE shop_order.id=".$id;
	$rs=$GLOBALS["conn"]->Execute($sSql);

	return $rs->fields["object"];
}

function getShopDiscount($total,$discount,$promos){
	if (strpos($discount, "%"))
	{
		$discount=str_replace("%", "", $discount);
		$order_discount=$promos*$discount*$total/100;
	}else
	$order_discount= $promos*$discount;
return $order_discount;
}
function getShopOrderPrice($id) {
	
	$sSql="SELECT 	Sum(shop_articles.price) as price 	FROM
	shop_orderline 	INNER JOIN shop_articles ON shop_articles.id = shop_orderline.articleId
	WHERE 	shop_orderline.orderId = ".$id;
	$rs=$GLOBALS["conn"]->Execute($sSql);
	
	return $rs->fields["price"];
	
}


function getObjByKey() {
	
//$table,$object,$keyname,$keyvalue
	$a = func_get_args();
	$table=$a[0];
	$object=$a[1];
    //$table.
	$sSql="select $object as object FROM ".$table." WHERE ";
	for( $t=2;$t<count($a);  ) {
		//	$pageUrl.=addParameter($a[$t++],$a[$t++]);
		$keyname="`".$a[$t++]."`";
		$keyvalue=$a[$t++];

		$sSql.=" UPPER($keyname) = UPPER('$keyvalue') and ";
	}
	$sSql.=" 1=1 ";
   // echo $sSql."<br/>";
	$rsobjbykey=$GLOBALS["conn"]->Execute($sSql);
   // echo $rs->RecordCount();
	if (!$rsobjbykey || 	$rsobjbykey->RecordCount()==0 ) return null;
	return $rsobjbykey->fields["object"];
}


function updateObjByKey() {
	//$table,$object,$keyname,$keyvalue
	$a = func_get_args();
	$table=$a[0];
	$key=$a[1];
	$value=$a[2];
	$sSql="UPDATE $table SET ";
	for( $t=3;$t<count($a);  ) {
		//	$pageUrl.=addParameter($a[$t++],$a[$t++]);
		$keyname=$a[$t++];
		$keyvalue=$a[$t++];
		$sSql.=" $keyname ='$keyvalue' ,";
	}
	$sSql=substr($sSql, 0, -1);
	$sSql.=" WHERE $key='$value'";
	
	echo $sSql."<br/>";
	
	$GLOBALS["conn"]->Execute($sSql);
}



function insertObjByKey() {
	//$table,$object,$keyname,$keyvalue
	$a = func_get_args();
	$table=$a[0];
	
	$total=((count($a)-1)/2)+1;
	
	//echo $total;
	
	$sSql="INSERT INTO $table (";
	
	for( $t=1;$t<$total;  ) {
		$sSql.=$a[$t++]." ,";
	}
	$sSql=substr($sSql, 0, -1);
	$sSql.=") VALUES(";
	for( $t=$total;$t<count($a);  ) {

        if ($a[$t]=="NOW()") $sSql.=$a[$t++]." ,"; else
		$sSql.="'".$a[$t++]."' ,";
	}
	$sSql=substr($sSql, 0, -1);
	$sSql.=");";

	//echo $sSql."<br/>";

	$GLOBALS["conn"]->Execute($sSql);
}



function removeObjByKey() {
    //$table,$object,$keyname,$keyvalue
    $a = func_get_args();
    $table=$a[0];

    //$total=((count($a)-1)/2)+1;
   // $total=((count($a)-1)/2)+1;

$total=count($a)-1;

    $sSql="DELETE FROM $table WHERE ";

    for( $t=1;$t<$total;  ) {
      //  echo "<br/>".$a[$t]."<br/>";
        $sSql.=$a[$t++]."='".$a[$t++]."' AND ";
    }
    $sSql.="1=1";
   // echo "<br/>".$sSql."<br/>";

    $GLOBALS["conn"]->Execute($sSql);
}


function Loadfile($path,$type)
{
	//<?php echo "/loadfile.php?file=".$path;
//if (strpos($path,"yamli")){
    if ($type=="js"){
	?>
	<script type="text/javascript" src="<?php echo $path; ?>"></script>
    <?php
    }elseif ($type=="css"){
        ?>
    <link rel="stylesheet" type="text/css" href="<?php echo $path; ?>"  media="screen"/>
    <?php
    //}
}

}


function log_action($msg) {

 if (isLocal() && false) {

     if(stripos($msg,"UPDATE")=== 0 ||  stripos($msg,"INSERT")=== 0 || stripos($msg,"DELETE")=== 0     ) {
         if (stripos($msg,"UPDATE `portal_logins` SET `profile`")!== 0 && stripos($msg,"INSERT INTO `portal_audittrail`")!== 0){
    $today = date("d_m_Y");
    $filename = "log_$today.log";


             $delimiter="/\\\/";
             if (!isLocal()) $delimiter="//";
             $tmp=preg_split($delimiter,getcwd());
             $tmp=$tmp[count($tmp)-1];

             if ($tmp=="portal")
             {
            $dir="../";
             }else $dir="./";

             if (!file_exists($dir.$filename)) {

                 echo chmod_11oo10($dir, "777");

             }

    $fd = fopen($dir.$filename, "a+");
     $msg = "/* [" . date("d/m/Y h:i:s", time()) . "] */ " . $msg;
            if (substr($msg,strlen($msg)-1)!=";") $msg .=";";
       //      echo getcwd();
//echo $dir.$filename;
    fwrite($fd, $msg. PHP_EOL);
    fclose($fd);

         }
     }
    }
}

function check_constraints($tb,$fd)
{
	$query    = "show create table $tb";
	$result   = ew_LoadRecordset($query);
	$tableDef = preg_split('/\n/',$result->fields[1]);


	$constraint_arg="";
	while (list($key,$val) = each($tableDef)) {


		$words=preg_split("/[\s'`()]+/", $val);
		//echo $words[5]."<br/>";
		if ($words[1] == "CONSTRAINT" && $words[6]=="REFERENCES") {
			if (strtoupper($words[5])==$fd) {
				$constraint_arg="  'values' => array(\n".
						"    'table'  => '$words[7]',\n".
						"    'column' => '$words[8]'\n".
						"  ),\n";
			}

		}
	}
	return $constraint_arg;
}


function chmod_11oo10($path, $mod)
{

return true;

    // set up basic connection
    $conn_id = ftp_connect("168.144.109.4");

    // login with username and password
    $login_result = ftp_login($conn_id, "f112832", "vox2hblb");

    $path="/webspace/httpdocs";

    // try to chmod $path directory
    if (ftp_site($conn_id, 'CHMOD '.$mod.' '."".$path) !== false) {
        $success=TRUE;
    }
    else {
        $success=FALSE;
    }

    // close the connection
    ftp_close($conn_id);
    return $success;
}

function prepareColumns($name,$lib){

  ?>
<script type="text/javascript">

    var Latinise={};Latinise.latin_map={"ÃƒÆ’Ã†â€™ÃƒÂ¯Ã‚Â¿Ã‚Â½":"A","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â®":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¶":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â°":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â²":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â´":"A","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¯Ã‚Â¿Ã‚Â½":"A","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¤":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¬":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¦":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¨":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Âª":"A","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"A","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã‚Â¾":"A","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¦":"A","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â ":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â ":"A","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"A","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¢":"A","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"A","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"A","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"A","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"A","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Âº":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"A","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Âº":"A","ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢":"A","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â²":"AA","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"AE","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¼":"AE","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¢":"AE","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â´":"AO","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¶":"AU","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¸":"AV","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Âº":"AV","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¼":"AY","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"B","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"B","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"B","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"B","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€ Ã¢â‚¬â„¢":"B","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"B","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"C","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã¢â‚¬â„¢":"C","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"C","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¹Ã¢â‚¬Â ":"C","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¹Ã¢â‚¬Â ":"C","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã‚Â ":"C","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"C","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â»":"C","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã‚Â½":"D","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¯Ã‚Â¿Ã‚Â½":"D","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"D","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã‚Â ":"D","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã¢â‚¬â„¢":"D","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã‚Â ":"D","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã‚Â½":"D","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â²":"D","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"D","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¯Ã‚Â¿Ã‚Â½":"D","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"D","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â±":"DZ","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"DZ","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"E","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"E","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã‚Â¡":"E","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¨":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã¢â‚¬Å“":"E","ÃƒÆ’Ã†â€™Ãƒâ€¦Ã‚Â ":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¾":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¹Ã…â€œ":"E","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"E","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¸":"E","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"E","ÃƒÆ’Ã†â€™Ãƒâ€¹Ã¢â‚¬Â ":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Âº":"E","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"E","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"E","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¹Ã…â€œ":"E","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¼":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã‚Â¡":"E","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Âª":"ET","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã‚Â¾":"F","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"F","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â´":"G","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã‚Â¾":"G","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¦":"G","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¢":"G","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã¢â‚¬Å“":"G","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â ":"G","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"G","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â ":"G","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¤":"G","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Âª":"H","ÃƒÆ’Ã‹â€ Ãƒâ€¦Ã‚Â¾":"H","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¨":"H","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¤":"H","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â§":"H","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¦":"H","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¢":"H","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¤":"H","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¦":"H","ÃƒÆ’Ã†â€™ÃƒÂ¯Ã‚Â¿Ã‚Â½":"I","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¬":"I","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¯Ã‚Â¿Ã‚Â½":"I","ÃƒÆ’Ã†â€™Ãƒâ€¦Ã‚Â½":"I","ÃƒÆ’Ã†â€™ÃƒÂ¯Ã‚Â¿Ã‚Â½":"I","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â®":"I","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â°":"I","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã‚Â ":"I","ÃƒÆ’Ã‹â€ Ãƒâ€¹Ã¢â‚¬Â ":"I","ÃƒÆ’Ã†â€™Ãƒâ€¦Ã¢â‚¬â„¢":"I","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¹Ã¢â‚¬Â ":"I","ÃƒÆ’Ã‹â€ Ãƒâ€¦Ã‚Â ":"I","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Âª":"I","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â®":"I","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"I","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¨":"I","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¬":"I","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â¹":"D","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â»":"F","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â½":"G","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"R","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"S","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"T","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â¬":"IS","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â´":"J","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€¹Ã¢â‚¬Â ":"J","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â°":"K","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¨":"K","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¶":"K","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â©":"K","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"K","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â²":"K","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¹Ã…â€œ":"K","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â´":"K","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"K","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"K","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¹":"L","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â½":"L","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â½":"L","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â»":"L","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¼":"L","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¶":"L","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¸":"L","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â ":"L","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¹Ã¢â‚¬Â ":"L","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Âº":"L","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¿":"L","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¢":"L","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¹Ã¢â‚¬Â ":"L","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¯Ã‚Â¿Ã‚Â½":"L","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"LJ","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¾":"M","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"M","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"M","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â®":"M","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€ Ã¢â‚¬â„¢":"N","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"N","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"N","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã‚Â ":"N","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"N","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"N","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¸":"N","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"N","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¹Ã¢â‚¬Â ":"N","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â ":"N","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"N","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"N","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã‚Â ":"NJ","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"O","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¦Ã‚Â½":"O","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"O","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¯Ã‚Â¿Ã‚Â½":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¹Ã…â€œ":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"O","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"O","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Âª":"O","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â®":"O","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â°":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã¢â‚¬â„¢":"O","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¯Ã‚Â¿Ã‚Â½":"O","ÃƒÆ’Ã‹â€ Ãƒâ€¦Ã¢â‚¬â„¢":"O","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã‚Â½":"O","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â ":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã‚Â¡":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã¢â‚¬Å“":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã‚Â¾":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â ":"O","ÃƒÆ’Ã‹â€ Ãƒâ€¦Ã‚Â½":"O","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¦Ã‚Â ":"O","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¦Ã¢â‚¬â„¢":"O","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¦Ã¢â‚¬â„¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¯Ã‚Â¿Ã‚Â½":"O","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã‚Â¸":"O","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Âª":"O","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¬":"O","ÃƒÆ’Ã†â€™Ãƒâ€¹Ã…â€œ":"O","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¾":"O","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã¢â‚¬â„¢":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã‚Â½":"O","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¬":"O","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¢":"OI","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¦Ã‚Â½":"OO","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"E","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"O","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¢":"OU","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"P","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"P","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"P","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¤":"P","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"P","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â£":"P","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¯Ã‚Â¿Ã‚Â½":"P","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¹Ã…â€œ":"Q","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"Q","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"R","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¹Ã…â€œ":"R","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¹Ã…â€œ":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã‚Â¡":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã¢â‚¬Å“":"R","ÃƒÆ’Ã‹â€ ÃƒÂ¯Ã‚Â¿Ã‚Â½":"R","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã‚Â¾":"R","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€¦Ã¢â‚¬â„¢":"R","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¤":"R","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¾":"C","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã‚Â½":"E","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¦Ã‚Â¡":"S","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¤":"S","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â ":"S","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¦":"S","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¦Ã‚Â¾":"S","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¦Ã¢â‚¬Å“":"S","ÃƒÆ’Ã‹â€ Ãƒâ€¹Ã…â€œ":"S","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â ":"S","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¢":"S","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¨":"S","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¤":"T","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¢":"T","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â°":"T","ÃƒÆ’Ã‹â€ Ãƒâ€¦Ã‚Â¡":"T","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¾":"T","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Âª":"T","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¬":"T","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¬":"T","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â®":"T","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â®":"T","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¦":"T","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¯":"A","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"L","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã¢â‚¬Å“":"M","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"V","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¨":"TZ","ÃƒÆ’Ã†â€™Ãƒâ€¦Ã‚Â¡":"U","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¬":"U","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"U","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¶":"U","ÃƒÆ’Ã†â€™Ãƒâ€¦Ã¢â‚¬Å“":"U","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"U","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"U","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"U","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â²":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¤":"U","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â°":"U","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"U","ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¦":"U","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¯":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¨":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â°":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Âª":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¬":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â®":"U","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"U","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Âª":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Âº":"U","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â²":"U","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â®":"U","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¨":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¸":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â´":"U","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¦Ã‚Â¾":"V","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¾":"V","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â²":"V","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¼":"V","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â ":"VY","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"W","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â´":"W","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"W","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"W","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¹Ã¢â‚¬Â ":"W","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"W","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â²":"W","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¦Ã¢â‚¬â„¢":"X","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¦Ã‚Â ":"X","ÃƒÆ’Ã†â€™ÃƒÂ¯Ã‚Â¿Ã‚Â½":"Y","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¶":"Y","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¸":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¦Ã‚Â½":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â´":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â²":"Y","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â³":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¶":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¾":"Y","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â²":"Y","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€¦Ã‚Â½":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¸":"Y","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¹":"Z","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â½":"Z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¯Ã‚Â¿Ã‚Â½":"Z","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â«":"Z","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â»":"Z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"Z","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¤":"Z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"Z","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Âµ":"Z","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â²":"IJ","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"OE","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"A","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¯Ã‚Â¿Ã‚Â½":"AE","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"B","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€ Ã¢â‚¬â„¢":"B","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"C","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"D","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"E","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â°":"F","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¢":"G","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"G","ÃƒÆ’Ã…Â Ãƒâ€¦Ã¢â‚¬Å“":"H","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Âª":"I","ÃƒÆ’Ã…Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€¦Ã‚Â ":"J","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"K","ÃƒÆ’Ã…Â Ãƒâ€¦Ã‚Â¸":"L","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€¦Ã¢â‚¬â„¢":"L","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¯Ã‚Â¿Ã‚Â½":"M","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â´":"N","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¯Ã‚Â¿Ã‚Â½":"O","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¶":"OE","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¯Ã‚Â¿Ã‚Â½":"O","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"OU","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€¹Ã…â€œ":"P","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€¦Ã‚Â½":"N","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"R","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â±":"S","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"T","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â»":"E","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€¦Ã‚Â¡":"R","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€¦Ã¢â‚¬Å“":"U","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€šÃ‚Â ":"V","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€šÃ‚Â¡":"W","ÃƒÆ’Ã…Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"Y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´Ãƒâ€šÃ‚Â¢":"Z","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¡":"a","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€ Ã¢â‚¬â„¢":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¯":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â·":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â±":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â³":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Âµ":"a","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã‚Â½":"a","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¢":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¥":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â­":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â§":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â©":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â«":"a","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¤":"a","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã‚Â¸":"a","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â§":"a","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¡":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¡":"a","ÃƒÆ’Ã‹â€ ÃƒÂ¯Ã‚Â¿Ã‚Â½":"a","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â ":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â£":"a","ÃƒÆ’Ã‹â€ Ãƒâ€ Ã¢â‚¬â„¢":"a","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¯Ã‚Â¿Ã‚Â½":"a","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¯Ã‚Â¿Ã‚Â½":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¦Ã‚Â¡":"a","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¥":"a","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â»":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¯Ã‚Â¿Ã‚Â½":"a","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¥":"a","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â£":"a","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â³":"aa","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¦":"ae","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â½":"ae","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â£":"ae","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Âµ":"ao","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â·":"au","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¹":"av","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â»":"av","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â½":"ay","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€ Ã¢â‚¬â„¢":"b","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"b","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"b","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"b","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¬":"b","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"b","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"b","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€ Ã¢â‚¬â„¢":"b","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Âµ":"o","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"c","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¯Ã‚Â¿Ã‚Â½":"c","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â§":"c","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"c","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"c","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"c","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"c","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¹Ã¢â‚¬Â ":"c","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¼":"c","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¯Ã‚Â¿Ã‚Â½":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"d","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¡":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¯Ã‚Â¿Ã‚Â½":"d","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¯Ã‚Â¿Ã‚Â½":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â­":"d","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¯Ã‚Â¿Ã‚Â½":"d","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"d","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"d","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã¢â‚¬â„¢":"d","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â±":"i","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â·":"j","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€¦Ã‚Â¸":"j","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"j","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â³":"dz","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"dz","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â©":"e","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"e","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"e","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â©":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¯Ã‚Â¿Ã‚Â½":"e","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Âª":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¿":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¯Ã‚Â¿Ã‚Â½":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€ Ã¢â‚¬â„¢":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"e","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â«":"e","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â¹":"e","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"e","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¨":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â»":"e","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"e","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"e","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¸":"e","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"e","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€šÃ‚Â½":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"e","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â«":"et","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€¦Ã‚Â¸":"f","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"f","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â®":"f","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"f","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Âµ":"g","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€¦Ã‚Â¸":"g","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â§":"g","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â£":"g","ÃƒÆ’Ã¢â‚¬Å¾ÃƒÂ¯Ã‚Â¿Ã‚Â½":"g","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¡":"g","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â ":"g","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¡":"g","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶Ãƒâ€ Ã¢â‚¬â„¢":"g","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¥":"g","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â«":"h","ÃƒÆ’Ã‹â€ Ãƒâ€¦Ã‚Â¸":"h","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â©":"h","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¥":"h","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¨":"h","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â§":"h","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â£":"h","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¥":"h","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¦":"h","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"h","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â§":"h","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"hv","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â­":"i","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â­":"i","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¯Ã‚Â¿Ã‚Â½":"i","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â®":"i","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¯":"i","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¯":"i","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"i","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"i","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¬":"i","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"i","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"i","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â«":"i","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¯":"i","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"i","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¨":"i","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â©":"i","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â­":"i","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Âº":"d","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â¼":"f","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¹":"g","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾Ãƒâ€ Ã¢â‚¬â„¢":"r","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"s","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"t","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â­":"is","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â°":"j","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Âµ":"j","ÃƒÆ’Ã…Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"j","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"j","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â±":"k","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â©":"k","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â·":"k","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Âª":"k","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€ Ã¢â‚¬â„¢":"k","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â³":"k","ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"k","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Âµ":"k","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"k","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¯Ã‚Â¿Ã‚Â½":"k","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"k","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Âº":"l","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã‚Â¡":"l","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¬":"l","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¾":"l","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â¼":"l","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â½":"l","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â´":"l","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â·":"l","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¹":"l","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¡":"l","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"l","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â»":"l","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"l","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â«":"l","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"l","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â­":"l","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"l","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"lj","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¿":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¦Ã¢â‚¬Å“":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¯Ã‚Â¿Ã‚Â½":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¸Ãƒâ€šÃ‚Â¿":"m","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¯Ã‚Â¿Ã‚Â½":"m","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€ Ã¢â‚¬â„¢":"m","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â±":"m","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¯":"m","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"m","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"n","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¹Ã¢â‚¬Â ":"n","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"n","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"n","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Âµ":"n","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"n","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"n","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¹":"n","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â²":"n","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"n","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€¦Ã‚Â¾":"n","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â°":"n","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"n","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â³":"n","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â±":"n","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã¢â‚¬â„¢":"nj","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â³":"o","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"o","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â´":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"o","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¶":"o","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â«":"o","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¯":"o","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â±":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"o","ÃƒÆ’Ã‹â€ ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â²":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¡":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â£":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€¦Ã‚Â¸":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¡":"o","ÃƒÆ’Ã‹â€ ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"o","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Âº":"o","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"o","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â«":"o","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â­":"o","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¸":"o","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€šÃ‚Â¿":"o","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Âµ":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¯Ã‚Â¿Ã‚Â½":"o","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â­":"o","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â£":"oi","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¯Ã‚Â¿Ã‚Â½":"oo","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"e","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"o","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â£":"ou","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"p","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"p","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"p","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¥":"p","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â±":"p","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶Ãƒâ€¹Ã¢â‚¬Â ":"p","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"p","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â½":"p","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"p","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"q","ÃƒÆ’Ã…Â Ãƒâ€šÃ‚Â ":"q","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"q","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"q","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"r","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"r","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹ÃƒÂ¯Ã‚Â¿Ã‚Â½":"r","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"r","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¾":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â³":"r","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€¦Ã‚Â¸":"r","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¼":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â²":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"r","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¯Ã‚Â¿Ã‚Â½":"r","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â½":"r","ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"c","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â¿":"c","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€¹Ã…â€œ":"e","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¿":"r","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¥":"s","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¡":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â§":"s","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€¦Ã‚Â¸":"s","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¯Ã‚Â¿Ã‚Â½":"s","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¡":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â£":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â©":"s","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â´":"s","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶Ãƒâ€¦Ã‚Â ":"s","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¿":"s","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¡":"g","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¯Ã‚Â¿Ã‚Â½":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¥":"t","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â£":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â±":"t","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Âº":"t","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¶":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"t","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¦":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â«":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â­":"t","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â­":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¯":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Âµ":"t","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â«":"t","ÃƒÆ’Ã…Â Ãƒâ€¹Ã¢â‚¬Â ":"t","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â§":"t","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Âº":"th","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¯Ã‚Â¿Ã‚Â½":"a","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"ae","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¯Ã‚Â¿Ã‚Â½":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â·":"g","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¥":"h","ÃƒÆ’Ã…Â Ãƒâ€šÃ‚Â®":"h","ÃƒÆ’Ã…Â Ãƒâ€šÃ‚Â¯":"h","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"i","ÃƒÆ’Ã…Â Ãƒâ€¦Ã‚Â¾":"k","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã‚Â¾ÃƒÂ¯Ã‚Â¿Ã‚Â½":"l","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¯":"m","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â°":"m","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â´ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"oe","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â¹":"r","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Â»":"r","ÃƒÆ’Ã¢â‚¬Â°Ãƒâ€šÃ‚Âº":"r","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¹":"r","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"t","ÃƒÆ’Ã…Â Ãƒâ€¦Ã¢â‚¬â„¢":"v","ÃƒÆ’Ã…Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"w","ÃƒÆ’Ã…Â Ãƒâ€¦Ã‚Â½":"y","ÃƒÆ’Ã‚ÂªÃƒâ€¦Ã¢â‚¬Å“Ãƒâ€šÃ‚Â©":"tz","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Âº":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â­":"u","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‚ï¿½":"u","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â»":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â·":"u","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼":"u","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¹Ã…â€œ":"u","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã‚Â¡":"u","ÃƒÆ’Ã¢â‚¬Â¡Ãƒâ€¦Ã¢â‚¬Å“":"u","ÃƒÆ’Ã¢â‚¬Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬Å“":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â³":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¥":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â±":"u","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"u","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¹":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â§":"u","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â°":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â©":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â±":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â«":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â­":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¯":"u","ÃƒÆ’Ã‹â€ ÃƒÂ¢Ã¢â€šÂ¬Ã¢â‚¬ï¿½":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â«":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â»":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â³":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¯":"u","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â©":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¹":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Âµ":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â«":"ue","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â¸":"um","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â´":"v","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€¦Ã‚Â¸":"v","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â¿":"v","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"v","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶Ãƒâ€¦Ã¢â‚¬â„¢":"v","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â±":"v","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¹Ãƒâ€šÃ‚Â½":"v","ÃƒÆ’Ã‚ÂªÃƒÂ¯Ã‚Â¿Ã‚Â½Ãƒâ€šÃ‚Â¡":"vy","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€ Ã¢â‚¬â„¢":"w","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Âµ":"w","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦":"w","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¡":"w","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Â°":"w","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¯Ã‚Â¿Ã‚Â½":"w","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â³":"w","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒâ€¹Ã…â€œ":"w","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¯Ã‚Â¿Ã‚Â½":"x","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¹":"x","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶ÃƒÂ¯Ã‚Â¿Ã‚Â½":"x","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â½":"y","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â·":"y","ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¿":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¯Ã‚Â¿Ã‚Â½":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Âµ":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â³":"y","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â´":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â·":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¿":"y","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â³":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢":"y","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¯Ã‚Â¿Ã‚Â½":"y","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â»Ãƒâ€šÃ‚Â¹":"y","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Âº":"z","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¾":"z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"z","ÃƒÆ’Ã…Â ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"z","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¬":"z","ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¼":"z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"z","ÃƒÆ’Ã‹â€ Ãƒâ€šÃ‚Â¥":"z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂºÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¢":"z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¶":"z","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚Â¶Ãƒâ€¦Ã‚Â½":"z","ÃƒÆ’Ã…Â ÃƒÂ¯Ã‚Â¿Ã‚Â½":"z","ÃƒÆ’Ã¢â‚¬Â Ãƒâ€šÃ‚Â¶":"z","ÃƒÆ’Ã¢â‚¬Â°ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"z","ÃƒÆ’Ã‚Â¯Ãƒâ€šÃ‚Â¬ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬":"ff","ÃƒÆ’Ã‚Â¯Ãƒâ€šÃ‚Â¬Ãƒâ€ Ã¢â‚¬â„¢":"ffi","ÃƒÆ’Ã‚Â¯Ãƒâ€šÃ‚Â¬ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¾":"ffl","ÃƒÆ’Ã‚Â¯Ãƒâ€šÃ‚Â¬ÃƒÂ¯Ã‚Â¿Ã‚Â½":"fi","ÃƒÆ’Ã‚Â¯Ãƒâ€šÃ‚Â¬ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡":"fl","ÃƒÆ’Ã¢â‚¬Å¾Ãƒâ€šÃ‚Â³":"ij","ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"oe","ÃƒÆ’Ã‚Â¯Ãƒâ€šÃ‚Â¬ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ":"st","ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÂ¯Ã‚Â¿Ã‚Â½":"a","ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã‹Å“":"e","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¢":"i","ÃƒÆ’Ã‚Â¢Ãƒâ€šÃ‚Â±Ãƒâ€šÃ‚Â¼":"j","ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢":"o","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â£":"r","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¤":"u","ÃƒÆ’Ã‚Â¡Ãƒâ€šÃ‚ÂµÃƒâ€šÃ‚Â¥":"v","ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œ":"x"};
    String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
    String.prototype.latinize=String.prototype.latinise;
$("#<?php echo $name; ?>").attr('readonly', true);
$("#<?php echo $lib; ?>").change(function() {
    $("#<?php echo $name; ?>").val($(this).val().latinize().replace(/[^\w]/gi, '').toLowerCase());
});
</script>
<?php

}


function filexists($file)
{
    $ps = explode(":", ini_get('include_path'));
    foreach($ps as $path)
    {
        if(file_exists($path.'/'.$file)) return true;
    }
    if(file_exists($file)) return true;
    return false;
}

function resize_image($dir,$image,$width,$height,$newname,$cropratio,$color,$quality=100){


if (!$image)
{

    echo 'Error: no image was specified';
   return null;
}

/*
define('CURRENT_DIR',			dirname(__FILE__));
define('CACHE_DIR_NAME',		'/imagecache/');
define('CACHE_DIR',				CURRENT_DIR . CACHE_DIR_NAME);
define('DOCUMENT_ROOT',			$_SERVER['DOCUMENT_ROOT']);
*/


// Images must be local files, so for convenience we strip the domain if it's there
$image			= preg_replace('/^(s?f|ht)tps?:\/\/[^\/]+/i', '', (string) $image);

// For security, directories cannot contain ':', images cannot contain '..' or '<', and
// images must start with '/'
if ($image{0} != '/' || strpos(dirname($image), ':') || preg_match('/(\.\.|<|>)/', $image))
{

//    echo 'Error: malformed image path. Image paths must begin with \'/\'';
  //  return null;
}

// If the image doesn't exist, or we haven't been told what it is, there's nothing
// that we can do
if (!$image)
{

    echo 'Error: no image was specified';
    return null;
}

// Strip the possible trailing slash off the document root
$dir=$_SERVER['DOCUMENT_ROOT'].$dir;
    //str_replace("/","\\",$dir);

if (!file_exists($dir . $image))
{

    echo 'Error: image does not exist: ' . $dir . $image;
    return null;
}

// Get the size and MIME type of the requested image
$size	= GetImageSize($dir . $image);
$mime	= $size['mime'];

// Make sure that the requested file is actually an image
if (substr($mime, 0, 6) != 'image/')
{

    echo 'Error: requested file is not an accepted type: ' . $dir . $image;
    return null;
}



$maxWidth		= (isset($width)) ? (int) $width : 0;
$maxHeight		= (isset($height)) ? (int) $height : 0;

if ($color)
    $color		= preg_replace('/[^0-9a-fA-F]/', '', (string) $color);
else
    $color		= FALSE;

// If either a max width or max height are not specified, we default to something
// large so the unspecified dimension isn't a constraint on our resized image.
// If neither are specified but the color is, we aren't going to be resizing at
// all, just coloring.
if (!$maxWidth && $maxHeight)
{
    $maxWidth	= 99999999999999;
}
elseif ($maxWidth && !$maxHeight)
{
    $maxHeight	= 99999999999999;
}
elseif ($color && !$maxWidth && !$maxHeight)
{
    $maxWidth	= $width;
    $maxHeight	= $height;
}



// If we don't have a max width or max height, OR the image is smaller than both
// we do not want to resize it, so we simply output the original image and exit
if ((!$maxWidth && !$maxHeight) || (!$color && $maxWidth >= $width && $maxHeight >= $height))
{
    $data	= file_get_contents($dir . $image);

    $lastModifiedString	= gmdate('D, d M Y H:i:s', filemtime($dir . $image)) . ' GMT';
    $etag				= md5($data);

    doConditionalGet($etag, $lastModifiedString);

  /*  header("Content-type: $mime");
    header('Content-Length: ' . strlen($data));
    echo $data;*/

}

// Ratio cropping
$offsetX	= 0;
$offsetY	= 0;

if ($cropratio)
{
    $cropRatio		= explode(':', (string) $cropratio);
    if (count($cropRatio) == 2)
    {
        $ratioComputed		= $width / $height;
        $cropRatioComputed	= (float) $cropRatio[0] / (float) $cropRatio[1];

        if ($ratioComputed < $cropRatioComputed)
        { // Image is too tall so we will crop the top and bottom
            $origHeight	= $height;
            $height		= $width / $cropRatioComputed;
            $offsetY	= ($origHeight - $height) / 2;
        }
        else if ($ratioComputed > $cropRatioComputed)
        { // Image is too wide so we will crop off the left and right sides
            $origWidth	= $width;
            $width		= $height * $cropRatioComputed;
            $offsetX	= ($origWidth - $width) / 2;
        }
    }
}

// Setting up the ratios needed for resizing. We will compare these below to determine how to
// resize the image (based on height or based on width)
$xRatio		= $maxWidth / $width;
$yRatio		= $maxHeight / $height;

if ($xRatio * $height < $maxHeight)
{ // Resize the image based on width
    $tnHeight	= ceil($xRatio * $height);
    $tnWidth	= $maxWidth;
}
else // Resize the image based on height
{
    $tnWidth	= ceil($yRatio * $width);
    $tnHeight	= $maxHeight;
}



// Before we actually do any crazy resizing of the image, we want to make sure that we
// haven't already done this one at these dimensions. To the cache!
// Note, cache must be world-readable

// We store our cached image filenames as a hash of the dimensions and the original filename
$resizedImageSource		= $tnWidth . 'x' . $tnHeight . 'x' . $quality;
if ($color)
    $resizedImageSource	.= 'x' . $color;
if ($cropratio)
    $resizedImageSource	.= 'x' . (string) $cropratio;
$resizedImageSource		.= '-' . $image;

$resizedImage	= $newname;

$resized		= $dir . $resizedImage;



// We don't want to run out of memory
ini_set('memory_limit', "100M");

// Set up a blank canvas for our resized image (destination)
$dst	= imagecreatetruecolor($tnWidth, $tnHeight);

// Set up the appropriate image handling functions based on the original image's mime type
switch ($size['mime'])
{
    case 'image/gif':
        // We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
        // This is maybe not the ideal solution, but IE6 can suck it
        $creationFunction	= 'ImageCreateFromGif';
        $outputFunction		= 'ImagePng';
        $mime				= 'image/png'; // We need to convert GIFs to PNGs
        $doSharpen			= FALSE;
        $quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
        break;

    case 'image/x-png':
    case 'image/png':
        $creationFunction	= 'ImageCreateFromPng';
        $outputFunction		= 'ImagePng';
        $doSharpen			= FALSE;
        $quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
        break;

    default:
        $creationFunction	= 'ImageCreateFromJpeg';
        $outputFunction	 	= 'ImageJpeg';
        $doSharpen			= TRUE;
        break;
}

// Read in the original image
$src	= $creationFunction($dir . $image);

if (in_array($size['mime'], array('image/gif', 'image/png')))
{
    if (!$color)
    {
        // If this is a GIF or a PNG, we need to set up transparency
        imagealphablending($dst, false);
        imagesavealpha($dst, true);
    }
    else
    {
        // Fill the background with the specified color for matting purposes
        if ($color[0] == '#')
            $color = substr($color, 1);

        $background	= FALSE;

        if (strlen($color) == 6)
            $background	= imagecolorallocate($dst, hexdec($color[0].$color[1]), hexdec($color[2].$color[3]), hexdec($color[4].$color[5]));
        else if (strlen($color) == 3)
            $background	= imagecolorallocate($dst, hexdec($color[0].$color[0]), hexdec($color[1].$color[1]), hexdec($color[2].$color[2]));
        if ($background)
            imagefill($dst, 0, 0, $background);
    }
}

// Resample the original image into the resized canvas we set up earlier
ImageCopyResampled($dst, $src, 0, 0, $offsetX, $offsetY, $tnWidth, $tnHeight, $size[0], $size[1]);

if ($doSharpen)
{
    // Sharpen the image based on two things:
    //	(1) the difference between the original size and the final size
    //	(2) the final size
    $sharpness	= findSharp($width, $tnWidth);

    $sharpenMatrix	= array(
        array(-1, -2, -1),
        array(-2, $sharpness + 12, -2),
        array(-1, -2, -1)
    );
    $divisor		= $sharpness;
    $offset			= 0;
    imageconvolution($dst, $sharpenMatrix, $divisor, $offset);
}



// Write the resized image to the cache
$outputFunction($dst, $resized, $quality);

// Put the data of the resized image into a variable
ob_start();
$outputFunction($dst, null, $quality);
$data	= ob_get_contents();
ob_end_clean();

// Clean up the memory
ImageDestroy($src);
ImageDestroy($dst);

// See if the browser already has the image
$lastModifiedString	= gmdate('D, d M Y H:i:s', filemtime($resized)) . ' GMT';
$etag				= md5($data);

doConditionalGet($etag, $lastModifiedString);



}


function findSharp($orig, $final) // function from Ryan Rud (http://adryrun.com)
{
    $final	= $final * (750.0 / $orig);
    $a		= 52;
    $b		= -0.27810650887573124;
    $c		= .00047337278106508946;

    $result = $a + $b * $final + $c * $final * $final;

    return max(round($result), 0);
} // findSharp()

function doConditionalGet($etag, $lastModified)
{
    header("Last-Modified: $lastModified");
    header("ETag: \"{$etag}\"");

    $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
        stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) :
        false;

    $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ?
        stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) :
        false;

    if (!$if_modified_since && !$if_none_match)
        return;

    if ($if_none_match && $if_none_match != $etag && $if_none_match != '"' . $etag . '"')
        return; // etag is there but doesn't match

    if ($if_modified_since && $if_modified_since != $lastModified)
        return; // if-modified-since is there but doesn't match

    // Nothing has changed since their last request - serve a 304 and exit
    header('HTTP/1.1 304 Not Modified');
    exit();
} // doConditionalGet()


function generate_thumb($dir,$img,$width,$height,$newimg){
resize_image($dir,$img,$width,$height,$newimg,null,"");
}

function getthumbname($img)
{
    $ext = ".".pathinfo($img, PATHINFO_EXTENSION);
    return str_replace($ext, "", $img."_thumb").$ext;
}


function emptyDatabase()
{
    ew_LoadRecordset('SET foreign_key_checks = 0');

    if ($rs = ew_LoadRecordset("SHOW TABLES"))
    {
        while(! $rs->EOF)
        {
            ew_LoadRecordset('DROP TABLE IF EXISTS '.$rs->fields[0]);

            $rs->MoveNext();
        }
    }

    ew_LoadRecordset('SET foreign_key_checks = 1');
}

function waterMarkImage($image,$stamp)
{

    $stamp = imagecreatefrompng($stamp);
    $im = imagecreatefromjpeg($image);



// Set the margins for the stamp and get the height/width of the stamp image
    $marge_right = 10;
    $marge_bottom = 10;
    $sx = imagesx($stamp);
    $sy = imagesy($stamp);

// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
    imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
    //ImageCopyResampled($dst, $src, 0, 0, $offsetX, $offsetY, $tnWidth, $tnHeight, $size[0], $size[1]);

// Output and free memory
   // header('Content-type: image/png');
    imagepng($im);
imagedestroy($im);

}


function blockUI($msg)
{

    ?>$.blockUI({ message: '<div class="loading"><?php echo $msg; ?></div>' });<?php echo "\n";

}

function unBlockUI()
{
    ?>$.unblockUI();<?php  echo "\n";
}

function LoggoutUser($sUsername)
{

    global $Security, $Language, $UserProfile;



        if (@$_COOKIE[EW_PROJECT_NAME]['AutoLogin'] == "") // Not autologin
            setcookie(EW_PROJECT_NAME . '[Username]', ""); // clear user name cookie
            setcookie(EW_PROJECT_NAME . '[Password]', ""); // clear password cookie
            setcookie(EW_PROJECT_NAME . '[LastUrl]', ""); // clear last URL

        // Clear Session ID cookie
        setcookie(EW_PROJECT_NAME . '[' . EW_USER_PROFILE_SESSION_ID . ']', ""); // Clear Session ID

        // Clear Session ID
        $UserProfile->SetValue(EW_USER_PROFILE_SESSION_ID, "");
        if (!$Security->IsSysAdmin())
            $UserProfile->SaveProfileToDatabase($sUsername);


        ew_WriteAuditTrailOnLogInOut($sUsername, $Language->Phrase("AuditTrailLogout"));

        // Unset all of the Session variables
        $_SESSION = array();

        // Delete the Session cookie and kill the Session
        if (isset($_COOKIE[session_name()]))
            setcookie(session_name(), '', time()-42000, '/');

        // Finally, destroy the Session
        @session_destroy();


}

function portalLogout()
{
	global $Security,$UserProfile;
	
	$sUsername = $Security->CurrentUserName();
	
	if (@$_COOKIE[EW_PROJECT_NAME]['AutoLogin'] == "") // Not autologin
		setcookie(EW_PROJECT_NAME . '[Username]', ""); // clear user name cookie
	setcookie(EW_PROJECT_NAME . '[Password]', ""); // clear password cookie
	setcookie(EW_PROJECT_NAME . '[LastUrl]', ""); // clear last URL
	
	// Clear Session ID cookie
	setcookie(EW_PROJECT_NAME . '[' . EW_USER_PROFILE_SESSION_ID . ']', ""); // Clear Session ID
	
	// Clear Session ID
	$UserProfile->SetValue(EW_USER_PROFILE_SESSION_ID, "");
	if (!$Security->IsSysAdmin())
		$UserProfile->SaveProfileToDatabase($sUsername);
	

//	ew_WriteAuditTrailOnLogInOut($sUsername, $Language->Phrase("AuditTrailLogout"));
	
	// Unset all of the Session variables
	$_SESSION = array();
	
	// Delete the Session cookie and kill the Session
	if (isset($_COOKIE[session_name()]))
		setcookie(session_name(), '', time()-42000, '/');
	
	// Finally, destroy the Session
	@session_destroy();
}

function ColumnExist($table,$column)
{

  $Sql="SELECT *  FROM information_schema.COLUMNS WHERE TABLE_NAME = '$table'  AND COLUMN_NAME = '$column'";
      $rs=$GLOBALS["conn"]->Execute($Sql);

    if ($rs==null) return false;

    if ($rs->RecordCount()==0) return false;

return true;
}

function TableExist($table)
{

	$Sql="SELECT 1  FROM $table";
	$rs=$GLOBALS["conn"]->Execute($Sql);

	if ($rs==null) return false;

	//if ($rs->RecordCount()==0) return false;

	return true;
}



function create_zip($files = array(),$destination = '',$overwrite = false) {
    //if the zip file already exists and overwrite is false, return false
    if(file_exists($destination) && !$overwrite) { return false; }
    //vars
    $valid_files = array();
    //if files were passed in...
    if(is_array($files)) {
        //cycle through each file
        foreach($files as $file) {
            //make sure the file exists
            if(file_exists($file)) {
                $valid_files[] = $file;
            }
        }
    }
    //if we have good files...
    if(count($valid_files)) {
        //create the archive
        $zip = new ZipArchive();
        if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
            return false;
        }
        //add the files
        foreach($valid_files as $file) {
            $new_filename = substr($file,strrpos($file,'/') + 1);
            $zip->addFile($file,$new_filename);
        }
        //debug
        //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

        //close the zip -- done!
        $zip->close();

        //check to make sure the file exists
        return file_exists($destination);
    }
    else
    {
        return false;
    }
}

function unzip($file,$dest)
{

    $zip = new ZipArchive;
    $res = $zip->open($file);
    if ($res === TRUE) {
        $zip->extractTo($dest);
        $zip->close();
        return true;
    } else {
       return false;
    }
}
function addGroupToUser($userId,$groupId)
{
    insertObjByKey("portal_groups_users","groupId","userId",$groupId,$userId);

}
function YamlifyCK($id)
{

?>

<script type="text/javascript">
    yamlifiyCK('<?php echo $id; ?>');
</script>
<?php

}


function Yamlify($id){
    global $lang;

    ?><script type="text/javascript">

 //   $(document).ready(function() {

 //alert("<?php echo $id; ?>")
    if (typeof(Yamli) == "object" && Yamli.init( { zIndexBase:5000 ,uiLanguage: "<?php echo $lang; ?>" , startMode: "onOrUserDefault" } ))
    {
      // alert("<?php echo $id; ?>")
        Yamli.yamlify( "<?php echo $id; ?>", { settingsPlacement: "bottomLeft" });

    }


   // });



</script><?php
}
function YamlifyType($id){
    global $lang;

    ?><script type="text/javascript">

   $(document).ready(function() {

    if (typeof(Yamli) == "object" && Yamli.init( { zIndexBase:5000 ,uiLanguage: "<?php echo $lang; ?>" , startMode: "onOrUserDefault" } ))
    {

        Yamli.yamlifyType ("<?php echo $id; ?>", { settingsPlacement: "bottomLeft" });

    }


   });



</script><?php
}
function makeRTE($field,$initialValue){
    @require_once("ckeditor/ckeditor.php");


    $CKEditor = new CKEditor();
    $config['toolbar'] = array(
        array( 'Source','-',
            'NewPage','Preview','Templates','-',
            'Cut','Copy','Paste','PasteText','PasteFromWord','-',
            'Undo','Redo','-',
            'Find','Replace','-',
            'SelectAll','RemoveFormat','-',
            'Maximize', 'ShowBlocks'),
        '/',
        array('Bold','Italic','Underline','Strike','-',
            'Subscript','Superscript','-',
            'NumberedList','BulletedList','-',
            'Outdent','Indent','Blockquote','-',
            'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-',
            'Link','Unlink','Anchor','-',
            'Image','Flash','Table','HorizontalRule','SpecialChar'
        ),
        '/',
        array('Format','Font','FontSize','-',
            'TextColor','BGColor')
    );
    $CKEditorOutput = $CKEditor->editor($field,$initialValue,$config);
}

function removeColumn($column){
?>
<script type="text/javascript">

$(document).ready(function(){


	$("#th_<?=$column?>").remove();
	$( "td[id$='_<?=$column?>']" ).remove();


});

	</script>
	
	<?php }
	
	
	function moveColumn($table,$columnFrom,$columnTo)
	{
		?>
		
		
<script>

$.moveColumn = function (table, from, to) {
    var rows = $('tr', table);
    var cols;
    rows.each(function() {
        cols = $(this).children('th, td');
        cols.eq(from).detach().insertBefore(cols.eq(to));
    });
}
var tbl = $('<?=$table?>');
$.moveColumn(tbl, <?=$columnFrom?>, <?=$columnTo?>);
</script>
		
		<?php 
		
	}

	
	function getMenu($parentId)
	{
		global $RootMenu,$Language,$LANG;
		
		$portalApplications=getPortalApplications();
	
	
		$sSql="SELECT * FROM portal_menu WHERE visible='Y' and parentId <=> $parentId order by orderCmpnt ASC";
			//echo $sSql;
		$rs=$GLOBALS["conn"]->Execute($sSql);
	
		$i=0;
	
	
		while ($rs && !$rs->EOF)
		{
	

			$curParentId=$parentId;
			if ($curParentId=="NULL") $curParentId=-1;
			$table=getObjByKey("portal_objects","name","id",$rs->fields["objectId"]);
			$table_app=@preg_split("/_/", $table)[0];
			if (in_array($table_app,$portalApplications))
			{
			$url="?table=".$table."&filter=1";
			if ((strpos($table,"_")!==false && strpos($table,"_")==0) || endsWith($table,"_")) $url="#";
			$RootMenu->AddMenuItem($rs->fields["id"], getObjByKey("portal_objects","lib_".$LANG,"id",$rs->fields["objectId"]), $url, $curParentId, "",canView("portal_objects", $rs->fields["objectId"]) ,$table);
			getMenu($rs->fields["id"]);//canView("portal_objects", $rs->fields["objectId"])
			}
			$rs->MoveNext();
		}
	
	}
	
	function isMappedTable($tablename)
	{
		$tmp=getObjByKey("portal_objects","mappedtoId","name",$tablename);
		if ($tmp!="") {
			return true;
		}
		
		return false;
	}
	
	
	
	
	
	function cabinet_setdentdefault($arr_dent,$dossierId)
	{
		global $portalId;
		$etatId=getObjByKey("cabinet_dent_default_etat","id","nom","Normal");
		foreach ($arr_dent as $dent){
			$SQL="INSERT IGNORE INTO cabinet_dent_default VALUES(null,$dossierId,'$dent',$etatId,$portalId);";
	
			//echo $SQL."<br/>";
			ew_ExecuteScalar($SQL);
		}
	}
	
	
	
	
	function Shop_printSubCategories($categoryId,$i,$targetPage){
		$i++;
		global $portalId,$LANG;
		$SQL="SELECT * FROM shop_category where portalId=$portalId and parentCategoryId=$categoryId Order by 	Ordercmpnt ASC ";
	
	
		//echo $SQL;
		$rs=ew_LoadRecordset($SQL);
	
		?>
	<div class="catgeory<?=$i?>">
	<ul>
	<?php 
	
	while ($rs && !$rs->EOF)  {
	
	    
	
	        $image=$rs->fields["image"]
		
			?>
	<li class="level<?=$i?>">
	<?php if ($image!="") {?>
	<img src="/<?=getFilesPath("categorypic")."/".$image?>"/>
	<?php } ?>
	<?php 
	  $categoryId= $rs->fields["id"];?>
	  <a href="/<?=$targetPage?>/<?=strtolower($rs->fields["category"])?>.html"><?=$rs->fields["lib_".$LANG]?></a>
	  <?php 
	  Shop_printSubCategories($categoryId,$i,$targetPage);
	  ?>
	  </li>
	  <?php 
	    
			
			
			$rs->MoveNext();
		}
		?>
		</ul></div>
		<?php 
			
		
	}
	
	
	function getDefaultAdminPage()
	{
		global $portalId;
		$SQL="SELECT
portal_objects.`name`,
portal_app.`name` AS appname
FROM
portal_menu
INNER JOIN portal_objects ON portal_objects.id = portal_menu.objectId ,
portal_portal_app
INNER JOIN portal_app ON portal_app.id = portal_portal_app.appId
WHERE
portal_menu.parentId IS NULL AND
portal_portal_app.portalId = $portalId AND
portal_objects.`name` LIKE CONCAT('%',portal_app.`name`,'%')
ORDER BY
portal_menu.orderCmpnt ASC limit 1";
	
		
		$rs=ew_LoadRecordset($SQL);
		
		return $rs->fields["name"];
	}
	
	
	function makeSelect($name,$id,$lib,$value,$table,$filtre,$cssClass)
	{
		global $portalId;
		if ($filtre!="") {$filtre="WHERE $filtre";
		
		$data=array();
	
		$data["portalId"]=$portalId;
		$filtre=TemplateWithData($filtre,$data);
		}
		$sSql="SELECT $lib as lib,$value as value FROM $table $filtre ";
		
		//echo $sSql;
		?>
		
		<select   name="<?=$name ?>" id="<?=$id ?>" class="<?=$cssClass ?>">
		<option value="none"></option>
		<?php
		
		      $rs2=$GLOBALS["conn"]->Execute($sSql); 
				
		 while ( !$rs2->EOF)  { 
		 	
				  ?>
		<option   value="<?php echo $rs2->fields["value"]; ?>"><?php echo $rs2->fields["lib"]; ?></option>
		
						  <?php
				  $rs2->MoveNext();    
				  }
		
		
			
		?>
		</select>
		<?php 
		
	}
	
	function safeDomName($string)
	{
		
		$string=strtolower($string);
		$string = str_replace(' ', '_', $string); // Replaces all spaces with hyphens.
		return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
		
	}
	
	function  addAjaxtoSelect($selectId,$table,$key,$value,$filter,$subSelectId,$tohide,$toshow)
	{
		
?>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
<?php $tohide_r=preg_split("#,#", $tohide);

foreach ($tohide_r as $hide)
{
	echo "$('#$hide').hide();";
}
?>



    $('#<?=$selectId?>').on('change', function (){
    	<?php $tohide_r=preg_split("#,#", $tohide);

    	foreach ($tohide_r as $hide)
    	{
    		echo "$('#$hide').hide();";
    	}
    	?>
    	
        $.getJSON('/portlet.php?app=system&operation=ajaxJsonSelect&table=<?=$table?>&filter=<?=$filter?>&key=<?=$key?>&value=<?=$value?>', {id: $(this).val()}, function(data){
            var options = '';
            for (var x = 0; x < data.length; x++) {
                options += '<option value="' + data[x]['key'] + '">' + data[x]['value'] + '</option>';
            }
            $('#<?=$subSelectId?>').html(options);
			if (data.length>1){
            <?php $toshow_r=preg_split("#,#", $toshow);
            
            foreach ($toshow_r as $show)
            {
            	echo "$('#$show').show();";
            }
			?>
			}
        });
    });
});
</script>
	<?php 
	}

	
	//updatepresentation tempale
	
/*	R::debug(true);
 $all = R::findAll('cabinet_dossier' );

 set_time_limit(0);
 R::begin();
 try{
 	

 $type=2;
 

 foreach ($all as $bean)
 {

 	$id=$bean->id;
 	//$SQL="UPDATE portal_presentationtemplate set type=$type where id=$id";nom=
 	$nom=substr($bean->nom, 0,1);
 	if (!isset($$nom)) $$nom=0; $$nom++;
$nd=$nom."/".substr($bean->dateDeCreation,2,2)."/".$$nom;
$bean->numeroDeDossier=$nd;
 	//R::store($bean);
 	echo $nd."<br/>";
 }
 
 R::commit();
 }
 catch(Exception $e) {
 	R::rollback();
 }*/
 
?>